PopupWindow 展开后点击返回键无效?

使用 PopupWindow 发现一个问题,在弹出PopupWindow后,点击展示内容的展示部分才会消失,而点击展示部分的上面区域无效,点击返回键也无效。

使用代码:

public class ListViewPopup extends PopupWindow {

    public ListViewPopup(final Context mContext, final ISelecterLinstener selector, final String[] list) {
        this.mContext = mContext;
        View view = View.inflate(mContext, R.layout.list_popup, null);
        ListView listView = (ListView) view.findViewById(R.id.mlv_popup);
        View blank = view.findViewById(R.id.blank);
        setContentView(view);
        this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
        this.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
        /**这个属性,加上 点击弹出框的上面的区域 弹框会消失。不加则点击无效*/
        this.setBackgroundDrawable(new ColorDrawable(0x555555));
        this.setOutsideTouchable(true);
        setFocusable(true);
    }
}

经测试,只有在Android6.0以下才会产生这样的问题。而Android6.0以上的手机是好的。

只需要加上这个设置就好了:

        this.setBackgroundDrawable(new ColorDrawable(0x555555));

在适配的路上举步维艰啊

发布了85 篇原创文章 · 获赞 46 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/jingbin_/article/details/94615298