Попробуйте добавить этот код
@Override
protected void onCreate(Bundle savedInstanceState) {
...
hideSystemUI(this, 1000);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
// Hide bar after 1 second
hideSystemUI(this, 1000);
}
}
public static void hideSystemUI(@NonNull final Activity activity, final int delayMs) {
View decorView = activity.getWindow().getDecorView();
int uiState = View.SYSTEM_UI_FLAG_IMMERSIVE
| 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
| View.SYSTEM_UI_FLAG_FULLSCREEN;
final Handler handler = new Handler();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if (visibility == View.VISIBLE) {
Runnable runnable = new Runnable() {
@Override
public void run() {
hideSystemUI(activity, 1000);
}
};
handler.postDelayed(runnable, delayMs);
}
}
});
decorView.setSystemUiVisibility(uiState);
}
ПРЕДУПРЕЖДЕНИЕ
Если у вас есть два действия, добавьте это перед изменением
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(null);