Android 版本兼容问题集锦

一、PopupWindow:
android 7.0之前,在指定位置弹出popupwindow可以用showAsDropDown(View anchor, int xoff, int yoff),showAtLocation(View parent, int gravity, int x, int y)。但在android 7.0上,用showAsDropDown()在popupwindow为全屏时,会有弹出位置异常情况,需用showAtLocation()才能正常显示:

if (Build.VERSION.SDK_INT < 24)
        {
            dropListPopupWindow.showAsDropDown(this, 0, 5);
        }
        else
        {
            // 适配 android 7.0
            int[] location = new int[2];
            getLocationOnScreen(location);
            int x = location[0];
            int y = location[1];
            Log.e(getClass().getSimpleName(), "x : " + x + ", y : " + y);
            dropListPopupWindow.showAtLocation(this, Gravity.NO_GRAVITY, 0, y + getHeight() + 5);
        }

你可能感兴趣的:(Android)