Android : 检查操作按钮(主页、后退等)是否在屏幕内?
Android : check wether action button (home,back, etc.. ) is inside the screen or not?
我想详细解释一下,
一些 android 设备有这样的操作按钮,
虽然有些设备有,
在第一种情况下,所有操作按钮都在屏幕外,而在第二种情况下,操作按钮位于屏幕底部(屏幕内)...我如何检测到操作按钮的位置?我不知道..!!
查看官方 Android 文档:http://developer.android.com/reference/android/view/KeyCharacterMap.html#deviceHasKey%28int%29
deviceHasKey方法可以解决你的问题。 (使用键码 KEYCODE_MENU、KEYCODE_HOME、KEYCODE_BACK)。
希望对你有帮助。
也许可以在您的 onCreate()
中执行以下检查:
api 14 岁及以上
boolean PermanentMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey(); // true if physical, false if virtual
较低api:
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
}
你可能会在这里得到你的答案。
Check for navigation bar
p.s。酒吧的正式名称是"Navigation Bar"
https://developer.android.com/training/system-ui/navigation.html
已找到解决方案 here,但不能 100% 保证适用于所有设备,某些设备(如 HTC、LAVA 等)无法使用该解决方案。 minApi 也需要 13+ 才能...!!
我想详细解释一下,
一些 android 设备有这样的操作按钮,
虽然有些设备有,
在第一种情况下,所有操作按钮都在屏幕外,而在第二种情况下,操作按钮位于屏幕底部(屏幕内)...我如何检测到操作按钮的位置?我不知道..!!
查看官方 Android 文档:http://developer.android.com/reference/android/view/KeyCharacterMap.html#deviceHasKey%28int%29
deviceHasKey方法可以解决你的问题。 (使用键码 KEYCODE_MENU、KEYCODE_HOME、KEYCODE_BACK)。 希望对你有帮助。
也许可以在您的 onCreate()
中执行以下检查:
api 14 岁及以上
boolean PermanentMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey(); // true if physical, false if virtual
较低api:
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
}
你可能会在这里得到你的答案。 Check for navigation bar
p.s。酒吧的正式名称是"Navigation Bar"
https://developer.android.com/training/system-ui/navigation.html
已找到解决方案 here,但不能 100% 保证适用于所有设备,某些设备(如 HTC、LAVA 等)无法使用该解决方案。 minApi 也需要 13+ 才能...!!