It's my solution:
First, define boolean that indicate if navigation bar is visible or not.
boolean navigationBarVisibility = true //because it's visible when activity is created
Second create method that hide navigation bar.
private void setNavigationBarVisibility(boolean visibility){
if(visibility){
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
navigationBarVisibility = false;
}
else
navigationBarVisibility = true;
}
By default, if you click to activity after hide navigation bar, navigation bar will be visible. So we got it's state if it visible we will hide it.
Now set OnClickListener to your view. I use a surfaceview so for me:
playerSurface.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setNavigationBarVisibility(navigationBarVisibility);
}
});
Also, we must call this method when activity is launched. Because we want hide it at the beginning.
setNavigationBarVisibility(navigationBarVisibility);