Skip to content

Instantly share code, notes, and snippets.

@ericosur
Last active July 31, 2024 07:39
Show Gist options
  • Save ericosur/c4fca1f792512d3b0b08a0bbb0043352 to your computer and use it in GitHub Desktop.
Save ericosur/c4fca1f792512d3b0b08a0bbb0043352 to your computer and use it in GitHub Desktop.
To hide navigation bar for android app
/*
* class WinHelper
*/
import android.app.Activity;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
class WinHelper {
public static void hideNavigationBar(Activity act) {
// Get the window's decor view
View decorView = act.getWindow().getDecorView();
// Get the WindowInsetsController (requires API level 30+)
WindowInsetsController controller = act.getWindow().getInsetsController();
if (controller != null) {
// Hide the navigation bars
controller.hide(WindowInsets.Type.navigationBars());
// Allow transient bars to appear on swipe gestures (optional)
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment