Last active
July 31, 2024 07:39
-
-
Save ericosur/c4fca1f792512d3b0b08a0bbb0043352 to your computer and use it in GitHub Desktop.
To hide navigation bar for android app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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