android - 以编程方式检测 onePlus One 设备中软导航栏的可用性?

标签 android

我需要检查设备是否有软导航栏,我遵循了建议here .

它工作得很好,除了在 onePlus 设备上,出于某种原因,这段代码:

int id = resources.getIdentifier("config_showNavigationBar", "bool", android");
    return id > 0 && resources.getBoolean(id);

返回 false,尽管显示了软导航栏。

知道如何才能得到正确的结果吗?

我不喜欢计算实际宽度和可用宽度,这似乎是昂贵的操作。

谢谢。

最佳答案

参见 this回答。不过,无法 100% 确定。

boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

if (hasBackKey && hasHomeKey) {
    // no navigation bar, unless it is enabled in the settings
} else {
    // 99% sure there's a navigation bar
}

编辑

另一种方法

public boolean hasNavBar (Resources resources) {
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
    return id > 0 && resources.getBoolean(id);
}

关于android - 以编程方式检测 onePlus One 设备中软导航栏的可用性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37699161/

相关文章:

javascript - 如何从已连接的 Android 设备查看 Cordova 日志消息?

android - 如何在我的应用程序中使用来自 Github 的代码

androidx.core :core-ktx:1. 7.0 没有任何修改就出现依赖错误?

预览自定义 View 中的 Android ResourceNotFoundException

java - 当后端更改需要更新的应用程序时如何强制更新应用程序

java - 无法在自定义 AlertDialog.Builder 上调用 Dismiss()

android - "Big"微调器的滚动条

java - 当闹钟时间与实时时间相差 1 小时的倍数时,PendingIntent 会触发 - Android

android - 处理谷歌地图时如何检测标记和多段线之间的截距

android - SearchManager - 添加自定义建议