[英]How to target devices with and without soft navigation keys (ie: Nexus 5, Galaxy S4)?
I was looking everywhere for an answer with no success. 我一直在四处寻找没有成功的答案。 I am using the values-xxhdpi folder to set my app's layout dimensions for the nexus 5, but as I switch to the galaxy S4 emulator (same resolution but without soft navigation keys) the layout is not ok any more.
我正在使用values-xxhdpi文件夹为nexus 5设置我的应用程序的布局尺寸,但是当我切换到银河S4仿真器(相同的分辨率,但没有软导航键)时,布局不再正常。
Is there a way to target devices having the same resolution with and without the soft navigation at the bottom of the screen? 是否可以使用屏幕底部的软导航来选择具有相同分辨率的设备?
Thanks! 谢谢!
use: 采用:
ViewConfiguration.hasPermanentMenuKey()
NOTE This only works for SDK >= 14 注意这仅适用于SDK> = 14
EDITED: 编辑:
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
}
You can detect whether a device has a hardware menu key or not (the method you can use to achieve that, is described for example here ) and apply a different set of resources yourself. 您可以检测设备是否具有硬件菜单键(例如, 此处描述了可用于实现该功能的方法),然后自己应用其他资源集。
There's no way to do that "automatically" for example by forcing an app to use a different drawable
folder. 无法通过强制应用程序使用其他
drawable
文件夹来“自动”执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.