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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31743309/article/details/78837581

在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);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_31743309/article/details/78837581