【虚拟按键】虚拟键适配PopupWindow显示位置

来源:互联网 发布:java打印杨辉三角10行 编辑:程序博客网 时间:2024/04/28 04:03

这里写图片描述

可以发现,虚拟键位,挡住了取消按钮的触控区域,网上百度一下,大多是在布局内家加上(Android:fitsSystemWindows=”true”) ,BUT我的控件不是布局,里面写好的啊!我采用的自定义布局,SO 问题就是如何让取消按钮的触控区域显示出来。

解决办法:获取虚拟键高度,然后定位显示布局的位置

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


使用的话  Point position = getNavigationBarSize(mContext);

position.y 就是需要的坐标

测试:虚拟键位正常显示在布局下面

这里写图片描述

链接地址:stackOverFlow

原文来自简书:http://www.jianshu.com/p/31d8c0097e47



0 0
原创粉丝点击