popupwindow在android7.0出现全屏解决方案

来源:互联网 发布:怎么设定网络熟读 编辑:程序博客网 时间:2024/06/01 08:13

在android7.0的版本测出popupwindow使用showAsDropDown方法之后,并不能显示在指定view的下方,而是全屏显示,只要重写showAsDropDown判断一下版本就好了.建议不要使用popupwindow了,使用DialogFragment代替,官方推荐的不要问为什么.

public class SingleFlowPopuwindow extends PopupWindow {    public SingleFlowPopuwindow (View contentView, int width, int height){        super(contentView,width,height);    }    @Override    public void showAsDropDown(View anchor) {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {            Rect visibleFrame = new Rect();            anchor.getGlobalVisibleRect(visibleFrame);            int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;            setHeight(height);        }        super.showAsDropDown(anchor);    }    @Override    public void showAsDropDown(View anchor, int xoff, int yoff) {        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {            Rect visibleFrame = new Rect();            anchor.getGlobalVisibleRect(visibleFrame);            int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;            setHeight(height);        }        super.showAsDropDown(anchor, xoff, yoff);    }}
阅读全文
0 0
原创粉丝点击