Check the major websites, finally combined with their own time, summed up two feasible methods
A. Modify the style file:
1. Add the Values-v19 folder, and then add the styles.xml to it:
<!--Base Application theme. -- <style name= "Apptheme" parent= "Theme.AppCompat.Light.NoActionBar" > <!-- Toolbar (Actionbar) Color-- <item name= "colorprimary" > @color/colorprimary</item> <!-- Status bar Color -<item name= "Colorprimarydark" > @color/colorprimary</item> <!--toolbar title color-- > <item name= "android:textcolorprimary" > @color/white</item> <!--window background color -- <item name= "Android:windowbackground" > @color/colorprimary</item> <!--translucent system bars-- > <item name= "Android:windowtranslucentstatus" >true</item> <item name= "Android: Windowtranslucentnavigation ">true</item> </style>
Two. Using the Open Source Library
Add dependencies in 1.android Studio:
'com.readystatesoftware.systembartint:systembartint:1.0.3'
2. Call the following method in the activity's OnCreate ():
/** * Apply KitKat specific translucency. */private void applykitkattranslucency () {//KitKat translucent Navigation/status bar. if (Build.VERSION.SDK_INT >= build.version_codes. KITKAT) {Settranslucentstatus (true); Systembartintmanager Mtintmanager = new Systembartintmanager (this); Mtintmanager.setstatusbartintenabled (TRUE); Mtintmanager.setnavigationbartintenabled (TRUE); Mtintmanager.settintcolor (0xf00099cc); Mtintmanager.settintdrawable (uielementshelper. Getgeneralactionbarbackground (this)); }} @TargetApi 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); }
At the end of the two methods above, add the following in the main layout:
Android:fitssystemwindows= "true"
Otherwise the title bar is white.
Implement android4.4 immersive title bar