检查导航栏 [英] Check for navigation bar
问题描述
我想检查一下Android的导航条是负载present这样我就可以相应地调整布局,没有任何人有什么建议?
I am trying to check to see whether the android navigation bar is present on load so that I can adjust a layout accordingly, does anyone have any suggestions?
这是导航栏,我试图检测:
This is the navigation bar I am trying to detect:
P.S。所有我发现至今都坏的方式,试图删除了吧,这是我不想做的事。
P.S. All I have found so far are 'bad' ways to try and remove the bar, which I dont want to do.
推荐答案
我花了一些时间,但我已经找到了一个更可靠的方法不是依靠 hasPermanentMenuKey()不为新工作手机一样的的HTC One 这没有菜单键,但确实有家庭及放大器;回键,以便不需要(或节目)软导航栏。为了解决这个试试下面的code这对于一个后退按钮检查过:
Took me some time but I've found a more reliable way than relying on hasPermanentMenuKey() which doesn't work for newer phones like the HTC One which have no menu key but do have home & back keys so don't need (or show) the soft navigation bar. To get around this try the following code which checks for a back button too:
boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
if(!hasMenuKey && !hasBackKey) {
// Do whatever you need to do, this device has a navigation bar
}
这篇关于检查导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!