How to hide the navigation bar and status bar in Android

one. remove status bar

The following is a code sample for Android to remove the status bar:

1. Add the following code in the Activity's onCreate() method:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

2. Add the following attribute to the Activity node in the AndroidManifest.xml file:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Note: This method will remove the entire status bar, including time, battery and other information. If you just want to hide the status bar without affecting other information, you can use the following code:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar();
if (actionBar != null) {     actionBar.hide(); }

This method will only hide the status bar, while other information (such as time, battery, etc.) will still be displayed.

two. How to remove the navigation bar

The first way:

1. Add the following code in the Activity's onCreate() method:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

2. Add the following attribute to the Activity node in the AndroidManifest.xml file:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Note: This method removes the entire navigation bar, including the back key, menu key, etc. If you just want to hide the navigation bar without affecting other functions, you can use the following code:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar ();
if (actionBar != null) {     actionBar.hide(); }

This method will only hide the navigation bar, while other functions (such as back key, menu key, etc.) will still be displayed.

The second way:

Add getSupportActionBar().hide(); in front of super.onCreate(savedInstanceState) of the onCreate method.

Guess you like

Origin blog.csdn.net/m0_67982986/article/details/131029580