Android_自定义底部动画弹出pupopwindow
16lz
2021-01-26
android_custom_pup.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/customPup_bt" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="显示底部弹出框"/>LinearLayout>
android_custom_pup_view.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffff00" android:orientation="vertical" > <Button android:id="@+id/custom_view_bt" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="可以点击" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="20px" android:layout_marginBottom="20px" android:text="这是一个自定义popupwindow" />LinearLayout>
activity
package com.lxf;import android.app.Activity;import android.content.Context;import android.graphics.drawable.ColorDrawable;import android.os.Bundle;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.view.WindowManager;import android.widget.Button;import android.widget.PopupWindow;import android.widget.Toast;/** * @address BeiJing * @author LiXufei * @function 自定义弹出框 */public class cCustomPupopwindow extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.android_custom_pup); /* * 展示底部弹出框 m,v8 */ findViewById(R.id.customPup_bt).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showPup(); } }); } protected void showPup() { //获得pup的view View view = LayoutInflater.from(cCustomPupopwindow.this).inflate(R.layout.android_custom_pup_view, null, false); //设置window的宽高 1 window的布局 2、window的宽 3、window的高 4、window是否获取焦点 PopupWindow window = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true); //设置window背景色 window.setBackgroundDrawable(new ColorDrawable(0x00000000)); //设置window动画 window.setAnimationStyle(R.style.custom_pup_style); //设置window在底部显示 window.showAtLocation(view, Gravity.BOTTOM, 0, 0); //获取view中的控件 Button bt = (Button) view.findViewById(R.id.custom_view_bt); bt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(cCustomPupopwindow.this, "这是一个自定义pupopwindow", 0).show(); } }); }}
style
更多相关文章
- android:ListView:convertView.setTag()来设置数据
- Android之时间戳的简单使用
- Android(安卓)拍照后显示照片
- 使用Notification发送消息通知
- Android(安卓)开发获取手机运行内存工具类
- android下为自己定义wifimanager类
- Android(安卓)TextView 一些字体颜色、大小设置属性
- Android(安卓)BaseFragment基类
- 第二章实例:Android窗口菜单显示