【问题标题】: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


【解决方案1】:

查看官方 Android 文档:http://developer.android.com/reference/android/view/KeyCharacterMap.html#deviceHasKey%28int%29

deviceHasKey 方法可以解决你的问题。 (使用键码 KEYCODE_MENU、KEYCODE_HOME、KEYCODE_BACK)。 希望对您有所帮助。

【讨论】:

    【解决方案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
    }
    

    【讨论】:

    【解决方案3】:

    您可以在这里得到答案。 Check for navigation bar

    附言栏的正式名称是“导航栏”
    https://developer.android.com/training/system-ui/navigation.html

    【讨论】:

      【解决方案4】:

      找到解决方案here,但不能 100% 保证适用于所有设备,某些设备(如 HTC、LAVA 等)无法使用。此外,minApi 需要 13+ 来实现...!!

      【讨论】:

        猜你喜欢
        • 2023-03-16
        • 2018-01-25
        • 2014-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多