美文网首页
关于PopWindow在底部展示时被华为虚拟键盘遮盖的问题

关于PopWindow在底部展示时被华为虚拟键盘遮盖的问题

作者: 晓风残月酒醒 | 来源:发表于2017-10-20 15:43 被阅读0次

    2017-10-18,在给领导展示自己新成果的时候又被打脸了,TMD我测试用的是小米的手机,结果领导的是华为的手机,展示底部PopWindow时最下面那一段被截掉了,废话不多说了,直接上代码:

    /**
     * 获取虚拟按键的高度
     * @param context
     * @return
     */
    public static Point getNavigationBarSize(Context context) {
        Point appUsableSize = getAppUsableScreenSize(context);
        Point realScreenSize = getRealScreenSize(context);
        // navigation bar on the right
        if (appUsableSize.x < realScreenSize.x) {
            return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
        }
        // navigation bar at the bottom
        if (appUsableSize.y < realScreenSize.y) {
            return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
        }
        // navigation bar is not present
        return new Point();
    }
    
    public static Point getAppUsableScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size =new Point();
        display.getSize(size);
        return size;
    }
    
    public static Point getRealScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size =new Point();
        if(Build.VERSION.SDK_INT>=17) {
            display.getRealSize(size);
        }else if(Build.VERSION.SDK_INT>=14) {
            try{
                size.x= (Integer) Display.class.getMethod("getRawWidth").invoke(display);
                size.y= (Integer) Display.class.getMethod("getRawHeight").invoke(display);
            }catch(IllegalAccessException e) {}catch(InvocationTargetException e) {}catch(NoSuchMethodException e) {}
        }
        return size;
    }

    相关文章

      网友评论

          本文标题:关于PopWindow在底部展示时被华为虚拟键盘遮盖的问题

          本文链接:https://www.haomeiwen.com/subject/vksvuxtx.html