PopWindow Android 7.0位置显示不准确以及Android 8.0全面屏显示导航键留白解决办法

popWindow 在Android7.0上的显示位置不管怎么设置都在屏幕的顶部,这是7.0的bug,已在7.1修复,但是7.0还是需要我们自己解决的,以及在小米mix2全面屏导航键留白,显示不全。

如图:


 方法如下:

 @Override
    public void showAsDropDown(View anchor) {
        if(Build.VERSION.SDK_INT >= 24) {
            Rect rect = new Rect();
            anchor.getGlobalVisibleRect(rect);
            int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom+anchor.getResources().getDimensionPixelSize(anchor.getResources().getIdentifier("navigation_bar_height", "dimen", "android"));
            setHeight(h);
        }
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
            int[] a = new int[2];
            anchor.getLocationInWindow(a);
            showAtLocation(anchor, Gravity.NO_GRAVITY, 0, a[1] + anchor.getHeight() + 0);
        }
        super.showAsDropDown(anchor);
    }
完美解决这俩大问题 !!睡觉睡觉。。。

猜你喜欢

转载自blog.csdn.net/yuejunfei/article/details/80928300
今日推荐