Skip to content

Commit

Permalink
【Android】Autohide navigation bar
Browse files Browse the repository at this point in the history
  • Loading branch information
skylersaleh committed Aug 4, 2023
1 parent 2029265 commit 58c4cd9
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,38 @@ public void onGlobalLayout(){
}
});

int currentApiVersion = android.os.Build.VERSION.SDK_INT;

final int flags = 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
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

// This work only for android 4.4+
if(currentApiVersion >= Build.VERSION_CODES.KITKAT){
getWindow().getDecorView().setSystemUiVisibility(flags);

// Code below is to handle presses of Volume up or Volume down.
// Without this, after pressing volume buttons, the navigation bar will
// show up and won't hide
final View decorView = getWindow().getDecorView();
decorView
.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
{
@Override
public void onSystemUiVisibilityChange(int visibility)
{
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
{
decorView.setSystemUiVisibility(flags);
}
}
});
}


}
@Override
public void onActivityResult(int requestCode, int resultCode,
Expand Down

0 comments on commit 58c4cd9

Please sign in to comment.