This question specific to the issue with Xiomi devices with MIUI over it.
How can I detect Fullscreen Mode (Gesture) or Navigation Button (soft navigation) is selected?
I Have tried a few solutions, but that does work on other devices but didn't work on Xiomi or MIUI.
I have tried this solution available on SO, so please provide another if you have.
public boolean hasNavBar (Resources resources)
{
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
return id > 0 && resources.getBoolean(id);
}
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
}
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.
}
}
});
Any idea of how can I get to know that the navigation bar is currently visible or not?
I also tried to calculate the real width and available width, it seems like MIUI always returning the reserved with of navigation bar.
Thanks.
There is no need to detect if Soft input navigation bar is visible or hidden for full screen activity you can create style and apply style to activity.
<style name="Theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">false</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
and add following line in activity :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
This is led you to stop the layout overlap from soft input navigation.