很多时候你可能会遇到popupwindow不显示或是一部分手机能显示一些不能显示的情况,那恭喜你看到了这篇文章
最开始我创建popupwindow的方式
代码如下
同理你也可以
最开始我创建popupwindow的方式
代码如下
//肉眼看上去没什么问题,果然拿出我的小米note跑起来也是正常的,但是偏偏来个三星和魅族的一些手机就显示不了 View view = LayoutInflater.from(this).inflate(R.layout.choice_rider_num, null); window = new PopupWindow(this); window.setContentView(view); window.setOutsideTouchable(false); window.setFocusable(true); // 实例化一个ColorDrawable颜色为半透明 window.setBackgroundDrawable(null); window.setAnimationStyle(R.style.mypopwindow_anim_style); window.showAtLocation(v, Gravity.BOTTOM, 0, 0);仔细研究后发现是没有给popupwindow设置宽高导致的,于是
window = new PopupWindow(this); window.setContentView(view); //设置宽高 window.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); window.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); window.setOutsideTouchable(false); window.setFocusable(true); window.setAnimationStyle(R.style.mypopwindow_anim_style); window.showAtLocation(v, Gravity.BOTTOM, 0, 0);解决啦
同理你也可以
window = new PopupWindow(v, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); window.setContentView(view) window.setOutsideTouchable(false); window.setFocusable(true); // 实例化一个ColorDrawable颜色为半透明 window.setBackgroundDrawable(null); window.setAnimationStyle(R.style.mypopwindow_anim_style); window.showAtLocation(v, Gravity.BOTTOM, 0, 0);参考: https://www.jianshu.com/p/a18215850a62