【发布时间】:2019-03-16 12:39:55
【问题描述】:
这个问题专门针对带有 MIUI 的小米设备的问题。
如何检测全屏模式(手势)或导航按钮(软导航)是否被选中?
我尝试了一些解决方案,但在其他设备上确实有效,但在小米或 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总是返回导航栏的reserved with。
谢谢。
【问题讨论】:
-
你有没有办法检查这个?我正在尝试做同样的事情
-
@moyo 即使我也有同样的问题