Five ways to hide status bar and title bar on Android
Method 1:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); // Hide the title bar requestWindowFeature(Window.FEATURE_NO_TITLE); // Hide the status bar getWindow().setFlags(.FLAG_FULLSCREEN, .FLAG_FULLSCREEN); setContentView(.activity_main); } }
Method 2:
<!-- Hide the status bar and title bar at the same time --> <activity android:name="" android:theme="@android:style/" android:label="@string/app_name" > <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity>
Method 3:
<!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <!-- Hide status bar --> <item name="android:windowFullscreen">true</item> <!-- Hide title bar --> <item name="android:windowNoTitle">true</item> </style>
Method 4: Dynamically display the hidden status bar
//Hide status bar lp = ().getAttributes(); |= .FLAG_FULLSCREEN; ().setAttributes(lp);
//Show the status bar attr = ().getAttributes(); &= (~.FLAG_FULLSCREEN); ().setAttributes(attr);
Method 5: Dynamically display the hidden status bar
The View class provides setSystemUiVisability and getSystemUiVisability methods, which implement dynamic display or hidden operations on the status bar, and obtain the current visibility of the status bar.
Analysis of the actual parameters passed in the setSystemUiVisibility method:
The actual parameters that can be passed in by the setSystemUiVisability(int visibility) method are:
1. View.SYSTEM_UI_FLAG_VISIBLE: Display the status bar,
Activity does not display in full screen (restore to normal state).
2. : Hide the status bar, and the Activity will be displayed in full screen.
3. View.SYSTEM_UI_FLAG_FULLSCREEN: Activity is displayed in full screen, and the status bar is hidden and overwritten.
4. View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN: Activity is displayed in full screen, but the status bar will not be hidden and overwritten, the status bar is still visible, and the top layout part of the Activity will be obscured by the status.
5. View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION: The effect is the same as View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
6. View.SYSTEM_UI_LAYOUT_FLAGS: The effect is the same as View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
7. View.SYSTEM_UI_FLAG_HIDE_NAVIGATION: Hide virtual buttons (navigation bar). Some phones use virtual buttons instead of physical buttons.
8. View.SYSTEM_UI_FLAG_LOW_PROFILE: The status bar display is in a low profile mode, and some icons on the status bar will be hidden.
package ; import ; import ; import ; import ; import ; import ; public class MainActivity extends Activity implements { @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); assignViews(); setOnClicks(); } private void setOnClicks() { (this); (this); (this); (this); (this); (this); (this); } private LinearLayout mMain; private TextView mTextview; private Button mButton1; private Button mButton2; private Button mButton3; private Button mButton4; private Button mButton5; private Button mButton6; private Button mButton7; private void assignViews() { mMain = (LinearLayout) findViewById(); mTextview = (TextView) findViewById(); mButton1 = (Button) findViewById(.button1); mButton2 = (Button) findViewById(.button2); mButton3 = (Button) findViewById(.button3); mButton4 = (Button) findViewById(.button4); mButton5 = (Button) findViewById(.button5); mButton6 = (Button) findViewById(.button6); mButton7 = (Button) findViewById(.button7); } @Override public void onClick(View v) { switch (()) { case .button1: //Activity is displayed in full screen, and the status bar is hidden and covered (View.SYSTEM_UI_FLAG_FULLSCREEN); ("Activity is displayed in full screen, and the status bar is hidden and overwritten\nView.SYSTEM_UI_FLAG_FULLSCREEN"); break; case .button2: (View.SYSTEM_UI_FLAG_VISIBLE); ("Restore to a stateful normal situation\nView.SYSTEM_UI_FLAG_VISIBLE"); break; case .button3: (); ("//Hide the status bar, and the Activity will stretch to full screen display\"); break; case .button4: (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); ("Activity is displayed in full screen, but the status bar will not be hidden and overwritten, the status bar is still visible, and the top layout part of the Activity will be obscured by the status\nView" + ".SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN \n View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION"); break; case .button5: (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); ("Activity full screen display, status bar transparent\nView.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION"); break; case .button6: (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); ("Hide virtual buttons\nView.SYSTEM_UI_FLAG_HIDE_NAVIGATION"); break; case .button7: (View.SYSTEM_UI_FLAG_LOW_PROFILE); ("The status bar is low-energy display, some will be hidden\nView.SYSTEM_UI_FLAG_LOW_PROFILE"); break; default: break; } } }