Studio, introducing an immersive compatibility library
Compile ' com.readystatesoftware.systembartint:systembartint:1.0.3 '
Eclipse, you can import the corresponding class.
First class, compatible with Actionbar
First step: Set activity Theme Android:theme= "@style/actionbartheme"
<style name= "actionbartheme" parent="Android: Theme.Holo.Light.DarkActionBar "><! -- API theme customizations can go to here. --><item name= "android: Actionbarstyle">@ style/actionbarstyle</item> </style><style name= "Actionbarstyle" parent="Android: Widget.Holo.Light.ActionBar.Solid.Inverse "><item name= "android: Background">@color/actionbar_bg</ item> </style>
Second step: Set the status bar transparent, and then set the status bar immersion color
@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); }
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); new SystemBarTintManager(this);tintManager.setStatusBarTintEnabled(true);//设置沉浸的颜色 tintManager.setStatusBarTintResource(R.color.statusbar_bg);}
Step three: Set the settings to fit windows, in the layout file
Android:fitssystemwindows= "true"
If not set, the UI of the app will top up, the system UI
Ok
The second type of activity without Actionbar
First step, set the theme, android:theme= "@style/fullbleedtheme"
<style name="FullBleedTheme" parent="android:Theme.Holo.Light.NoActionBar"><!-- API 14 theme customizations can go here. --></style>
<style name="FullBleedTheme" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor"><!-- API 19 theme customizations can go here. --></style>
Or
Only Theme.AppCompat.NoActionBar themes can be set with toolbar
<style name =< Span class= "hljs-string" > "Appthemetoolbar" parent= "Theme.AppCompat.NoActionBar" > <item name =" colorprimary " > #2196F3 </item> <item name =" Colorprimarydark " > #2196F3 </item> <! --<item name= "Colorprimarydark" > #1565C0 </item>--> <item name = " Coloraccent " > #E91E63 </item> </style>
Step two: Same as the previous second step.
Set the status bar transparency + color
new SystemBarTintManager(this);mTintManager.setStatusBarTintEnabled(true);mTintManager.setNavigationBarTintEnabled(true); mTintManager.setStatusBarTintResource(R.color.statusbar_bg);
Step Three:
Android:fitssystemwindows= "true"
Android:cliptopadding= "false"
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android immersive status bar implementation details