//找布局
View inflate = LayoutInflater.from(MainActivity.this).inflate(R.layout.popu_item,null);//创建popupWindow
final PopupWindow popupWindow =new PopupWindow(inflate, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//设置动画
popupWindow.setAnimationStyle(R.style.Animation_Design_BottomSheetDialog);
//设置获取焦点
popupWindow.setFocusable(true);
//设置可触摸
popupWindow.setTouchable(true);
//设置外部可以点击
popupWindow.setOutsideTouchable(true);
//设置空背景,必须加上,可以让外部点击事件被触发
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//点击空白处消失
popupWindow.setBackgroundDrawable(new ColorDrawable());
popupWindow.setOutsideTouchable(true);
popupWindow.showAtLocation(img, Gravity.CENTER,0,0)
<!--简单布局-->
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
android:layout_gravity="center"
android:id="@+id/btn1"
android:text="打开相机"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_gravity="center"
android:id="@+id/btn2"
android:text="打开相册"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_gravity="center"
android:id="@+id/btn3"
android:text="取消"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
网友评论