Working on a client\'s app that is using immersive mode to hide the navigation bar and status bar on every activity using the following code:
int currentApiV
I've come up with a workaround that checks the navigation bar's status for every internal, try to hide it and check it again (and again).
Here's some piece of code, that makes sure the navigation bar is hidden in 2 seconds after the soft keyboard is closed.
private final Runnable checkSystemUiRunnable = new Runnable() {
@Override
public void run() {
checkHideSystemUI();
}
};
private void checkHideSystemUI() {
// Check if system UI is shown and hide it by post a delayed handler
if (isSystemUiShown) {
hideSystemUI();
handler.postDelayed(checkSystemUiRunnable, SYSTEM_UI_HIDE_DELAY);
}
}
private void hideSystemUI() {
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
// In onCreate()
decorView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
handler.postDelayed(checkSystemUiRunnable, SYSTEM_UI_HIDE_DELAY);
isSystemUiShown = true;
} else {
isSystemUiShown = false;
}
}
});