To implement the immersive status bar above Android 4.4 use open source project Systembartint (Https://github.com/hexiaochun/SystemBarTint)
Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); if(Build.VERSION.SDK_INT >=Build.version_codes. KITKAT) {Settranslucentstatus (true); } Systembartintmanager Tintmanager=NewSystembartintmanager ( This); Tintmanager.setstatusbartintenabled (true); Tintmanager.setstatusbartintresource (R.drawable.back); } @TargetApi (19) Public voidSettranslucentstatus (BooleanOn ) {Window win=GetWindow (); Windowmanager.layoutparams Winparams=win.getattributes (); Final intBITS =WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if(ON) {Winparams.flags|=bits; } Else{winparams.flags&= ~bits; } win.setattributes (Winparams); }
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:fitssystemwindows= "true"Android:cliptopadding= "true" Android:background= "#ffffff"android:orientation= "vertical" > <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "100DP"Android:background= "#009959" /> <ButtonAndroid:layout_width= "100DP"Android:layout_height= "50DP"Android:background= "#ff669d"/> </LinearLayout>
Android:fitssystemwindows= "true" : Sets whether the System window layout is considered when the layout is applied and, if true, adjusts the system window layout to fit your custom layout. For example, the system has a status bar, the application also has a status bar.
Android:cliptopadding= "true" : The property defines whether ViewGroup is allowed to be drawn in padding, which defaults to true, which is not allowed.
The effect is as follows:
Android 4.4 Immersive status bar implementation