android 7.0 PopupWindow中ShowAsDropDown()方法不适配的解决方案

来源:互联网 发布:杨幂用什么软件直播 编辑:程序博客网 时间:2024/05/31 13:15

方法:

     在你extends的PopupWindow中添加如下代码:

     

    @Override
    public void showAsDropDown(View anchor) {//为了适配android 7.0以上的showAsDropDown失效的问题
        if (Build.VERSION.SDK_INT >= 24) {
            Rect rect = new Rect();
            anchor.getGlobalVisibleRect(rect);
            int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
            setHeight(h);
        }
        super.showAsDropDown(anchor);
    }

阅读全文
0 0
原创粉丝点击