网站客服:zx81024163 |

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

2023-07-25 03:02:49发布    浏览456次    信息编号:65647

友情提醒:凡是以各种理由向你收取费用,均有骗子嫌疑,请提高警惕,不要轻易支付。

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

可以发现,虚拟键位遮挡了取消按钮的触摸区域。 网上百度搜一下,大部分都是在布局中添加(:=”true”)的,但是我的控件不是布局,是写在里面的! 我正在使用自定义布局,所以问题是如何使取消按钮的触摸区域显示出来。

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

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 = ();

.y 是所需的坐标

测试:布局下虚拟按键正常显示

链接地址:

原文来自简书:

提醒:请联系我时一定说明是从星空网上看到的!