How can I detect the presence of the navigation bar and hide it?
In my onCreate()
I call hideNavigationBar()
method to hide the navigation bar, then I register a listener to hide the navigation bar every time it becomes visible when the user touches anywhere on the screen as reported by the documentations. When the navigation bar becomes visible after a touch event the hideNavigationBar()
method is called again by the listener, but it has not effect, the bar is still visible.
This is my onCreated()
method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hideNavigationBar();
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
Toast.makeText(getApplicationContext(), "Visible", Toast.LENGTH_SHORT).show();
hideNavigationBar();
} else {
Toast.makeText(getApplicationContext(), "Not visible", Toast.LENGTH_SHORT).show();
}
}
});
}
and this is my hideNavigationBar()
method:
private void hideNavigationBar() {
Toast.makeText(getApplicationContext(), "hideNavigationBar()", Toast.LENGTH_SHORT).show();
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
How can I hide the navigation bar every time it becomes visible?
Thanks