当前位置:   article > 正文

android PopupWindow的简单使用_安卓popupwindow的简单使用

安卓popupwindow的简单使用

实现思路:1、获取到根view 2、获取到要弹出的view 3、确定位置并弹出(同时背景变暗)4、触摸弹框外弹框消失,背景恢复

  1. //获取根view
  2. mRootView=LayoutInflater.from(EditCameraActivity.this).inflate(R.layout.activity_edit_camera, null);
  3. //获取弹出view
  4. mPopView=LayoutInflater.from(EditCameraActivity.this).inflate(R.layout.popupwindow,null);
  5. //创建PopupWindow
  6. mPopupWindow = new PopupWindow(mPopView,
  7. LinearLayout.LayoutParams.MATCH_PARENT,
  8. LinearLayout.LayoutParams.WRAP_CONTENT,true);
  9. //设置触摸背景时使弹出框消失
  10. mPopupWindow.setOutsideTouchable(true);
  11. //设置弹出框内部控件可点击
  12. mPopupWindow.setFocusable(true);
  13. //弹出框消失时,背景不再灰暗
  14. mCommitPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
  15. @Override
  16. public void onDismiss() {
  17. WindowManager.LayoutParams lp = getWindow().getAttributes();
  18. lp.alpha = 1f;
  19. getWindow().setAttributes(lp);
  20. }
  21. });
  22. //更改弹出时背景的透明度
  23. WindowManager.LayoutParams lp = getWindow().getAttributes();
  24. lp.alpha = 0.4f;
  25. getWindow().setAttributes(lp);
  26. //确定弹出的位置并弹出
  27. mPopupWindow.showAtLocation(mRootView, Gravity.BOTTOM,0,0);

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/841073
推荐阅读
相关标签
  

闽ICP备14008679号