实用地检测MIUI /小米设备中的软导航栏可用性?

问题描述 投票:0回答:1

这个问题特定于小米设备与MIUI的问题。

如何选择全屏模式(手势)或导航按钮(软导航)?

我尝试了一些解决方案,但这在其他设备上有效但在Xiomi或MIUI上无效。

我已经在SO上尝试过这个解决方案,所以如果你有,请提供另一个解决方案。

1

public boolean hasNavBar (Resources resources) 
{
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
    return id > 0 && resources.getBoolean(id);
}

2

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

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
                    // TODO: The navigation bar is visible. Make any desired
                    // adjustments to your UI, such as showing the action bar or
                    // other navigational controls.
                } else {
                    // TODO: The navigation bar is NOT visible. Make any desired
                    // adjustments to your UI, such as hiding the action bar or
                    // other navigational controls.
                }
            }
        });

知道怎样才能知道导航栏当前是否可见?

我也尝试计算实际宽度和可用宽度,似乎MIUI总是返回保留的导航栏。

谢谢。

java android xiaomi miui
1个回答
1
投票

无需检测软输入导航栏是否可见或隐藏用于全屏活动,您可以创建样式并将样式应用于活动。

 <style name="Theme" parent="Theme.AppCompat.Light.NoActionBar">
         <item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">false</item>
         <item name="android:windowTranslucentStatus">true</item>
     </style>

并在活动中添加以下行:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

这导致您从软输入导航中停止布局重叠。

© www.soinside.com 2019 - 2024. All rights reserved.