【问题标题】:How to target devices with and without soft navigation keys (ie: Nexus 5, Galaxy S4)?如何定位带和不带软导航键的设备(即:Nexus 5、Galaxy S4)?
【发布时间】:2015-10-22 08:53:03
【问题描述】:

我到处寻找答案,但没有成功。我正在使用 values-xxhdpi 文件夹为 nexus 5 设置我的应用程序的布局尺寸,但是当我切换到 Galaxy S4 模拟器(相同的分辨率但没有软导航键)时,布局不再正常。

有没有办法在屏幕底部有和没有软导航的情况下定位具有相同分辨率的设备?

谢谢!

【问题讨论】:

    标签: android layout styles screen-size softkeys


    【解决方案1】:

    使用:

    ViewConfiguration.hasPermanentMenuKey()
    

    注意 这仅适用于 SDK >= 14

    已编辑:

    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
    }
    

    【讨论】:

      【解决方案2】:

      您可以检测设备是否具有硬件菜单键(您可以用来实现该功能的方法,例如 here 进行了描述)并自己应用一组不同的资源。

      无法“自动”执行此操作,例如强制应用使用不同的 drawable 文件夹。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-12
        • 2013-12-19
        相关资源
        最近更新 更多