我需要检查设备是否有软导航栏,我遵循了建议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/