1. 程式人生 > >PopWindow Android 7.0位置顯示不準確以及Android 8.0全面屏顯示導航鍵留白解決辦法

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);
    }
完美解決這倆大問題 !!睡覺睡覺。。。