【问题标题】:Android : check wether action button (home,back, etc.. ) is inside the screen or not?Android:检查操作按钮(主页、返回等)是否在屏幕内?
【发布时间】:2015-06-16 23:26:54
【问题描述】:
我想更详细地解释一下,
一些安卓设备有这样的动作按钮,
虽然有些设备喜欢,
在第一种情况下,所有操作按钮都在屏幕外,而在第二种情况下,操作按钮位于屏幕底部(屏幕内)...我如何检测到操作按钮所在的位置?我不知道它..!!
【问题讨论】:
标签:
android
android-layout
android-activity
【解决方案2】:
也许通过在您的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
}
【解决方案4】:
找到解决方案here,但不能 100% 保证适用于所有设备,某些设备(如 HTC、LAVA 等)无法使用。此外,minApi 需要 13+ 来实现...!!