Android immersive status bar Implementation Details
Introduce immersive compatible libraries in studio
Compile 'com. readystatesoftware. systembartint: 1.0.3'
Eclipse, You can import the corresponding class.
Class 1, compatible with actionbar
Step 1: Set the activity topic android: theme = "@ style/action1_eme"
Step 2: Set the status bar transparency, and then set the immersion color of the status bar
@TargetApi(19)private void setTranslucentStatus(boolean on) {Window win = getWindow();WindowManager.LayoutParams winParams = win.getAttributes();final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); if (Build. VERSION. SDK_INT> = Build. VERSION_CODES.KITKAT) {setTranslucentStatus (true);} SystemBarTintManager tintManager = new SystemBarTintManager (this); tintManager. setStatusBarTintEnabled (true); // sets the immersed color tintManager. setStatusBarTintResource (R. color. statusbar_bg );}
Step 3: Set to adapt to windows and set the layout File
Android: fitsSystemWindows = "true"
If this parameter is not set, the application ui will be topped up and pushed to the system ui.
OK
Activity Without actionbar
Step 1: Set the topic, android: theme = "@ style/FullBleedTheme"
Or
Only Theme. AppCompat. NoActionBar themes can be set with toolbar.
Step 2: Same as step 2.
Set the status bar transparency + color
mTintManager = new SystemBarTintManager(this);mTintManager.setStatusBarTintEnabled(true);mTintManager.setNavigationBarTintEnabled(true); mTintManager.setStatusBarTintResource(R.color.statusbar_bg);
Step 3:
Android: fitsSystemWindows = "true"
Android: clipToPadding = "false"