Android 5.0 and above implementation (Android after 5.0 introduced material Design implementation in a relatively simple way) transparent status bar, the background is immersed in the status bar
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}
The view default Fitssystemwindows value in the layout file is false so you will see that the entire layout starts at the top, and if there is textview at the top of the layout you will see the status bar covering TextView. In this case, you can set up for a specific layout
android:fitsSystemWindows="true"
Which view sets this property to True, the system adjusts the view's padding value to allow space for the system form. Padding the status bar to the status bar, so we don't define layout to overlap the status bar!
Coloring status Bar
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); // 有些情况下需要先清除透明flag window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(getResources().getColor(R.color.green));}
//--------------------------------------------------------Android Status Bar Tool class (for immersive status bar/discoloration status bar)
Blog Source: http://laobie.github.io/android/2016/03/27/statusbar-util.html
Test results:
Huawei Glory 4 A Android version 5.1.1 status bar is always unable to adjust (also cannot adjust the status bar, is the Huawei system itself prohibits the status bar).
Millet 4 can be adjusted.
This is a tool class for setting the status bar for Android APP, which can be used to change the status bar/status bar color in 4.4 and above system, support setting the status bar transparency, and meet the various requirements (fog) of your department designer.
Prior to this I wrote an android App immersive status bar solution, then our designer said the default transparency is too deep, let me change a little bit, and then after thinking about some ways to solve. In line with the principle of not repeating the wheel, simply organize into a tool class, convenient for developers.
Project GitHub Address
Sample Download
Download Statusbarutil-demo
Feature 1. Set the status bar color
StatusBarUtil.setColor(Activity activity, int color)
2. Set the status bar translucent
StatusBarUtil.setTranslucent(Activity activity, int statusBarAlpha)
3. Set the status bar to full transparency
StatusBarUtil.setTransparent(Activity activity)
4. To include
DrawerLayoutinterface to set the status bar color (can also be set to translucent and fully transparent)
statusbarutil.< Span class= "NA" style= "color: #a6e22e" >setcolorfordrawerlayout (activity activitydrawerlayout Drawerlayoutint color)
5. By passing in
statusBarAlphaparameter, the transparency value of the status bar can be changed, and the default value is 112. Use 1. To add dependencies in the Build.gradle file, Statusbarutil has been published in Jcenter:
compile ‘com.jaeger.statusbaruitl:library:1.0.0‘
2. In
setContentView()Then call the method you want, for example:
setcontentview (r. Layout. Main_activity ... statusbarutil.setcolor ( Mainactivity. Thismcolor)
3. If you are in a containing
DrawerLayoutinterface, you need to use it in the layout file for
DrawerLayoutAdd to
android:fitsSystemWindows="true"Property:
<android.support.v4.widget.drawerlayoutxmlns:android= "http://schemas.android.com/apk/res/android" xmlns:app="http// Schemas.android.com/apk/res-auto " android:id=" @+id/drawer_layout " android:layout_width=" Match_ Parent " android:layout_height=" match_parent " android:fitssystemwindows=" true "> ... </android.support.v4.widget.DrawerLayout>
4. When you set the
statusBarAlphaValue, the value needs to be between 0 and 255
Android Transparent status bar & coloring status bar