Background: Because the last time the boss asked me if our app could customize the status bar above I said yes! At that time did not control, today tried a lot of pits, before GitHub there are a lot of big Guy wrote an open source library interested can point in to see the support drawlayout immersion type [Statusbarutil] (https://github.com/laobie/ Statusbarutil feel good, like the big guy salute, I am a small, I can only use the most stupid way!
first of all, about the status bar when the system version is 4.4 or more than 4.4 can use the immersive status bar implementation of the code in fact the status bar is not very difficult, that is, by adding a view with the same State bar, but you have to calculate the height of the status bar will appear ghosting or the top, haha! Below to see how I went on top, very powerful yo!
* Dynamic Setup status bar for immersive status bar * */Private void initstate() {The immersive status bar can be used when the system version is 4.4 or above 4.4 if(Build.VERSION.SDK_INT >= build.version_codes. KITKAT) {//Transparent status barGetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//Transparent navigation barGetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);//LinearLayout Linear_bar = (linearlayout) Findviewbyid (R.id.ll_bar); Linear_bar.setvisibility (view.visible);//Gets the height of the status bar intStatusheight = Getstatusbarheight ();//dynamically set the height of the hidden layoutLinearlayout.layoutparams params = (linearlayout.layoutparams) linear_bar.getlayoutparams (); Params.height = Statusheight; Linear_bar.setlayoutparams (params); } }/** * Get status bar height by reflection * * @return * * Private int Getstatusbarheight() {Try{class<?> c = class.forname ("Com.android.internal.r$dimen"); Object obj = c.newinstance (); Field field = C.getfield ("Status_bar_height");intx = Integer.parseint (Field.get (obj). toString ());returnGetresources (). getdimensionpixelsize (x); }Catch(Exception e) {E.printstacktrace (); }return 0; }}
I directly encapsulated here to my baseactivity because each activity ' write code slice ' all need to use, the code is not difficult, think of our predecessors so many of their hard-written things all contribute to the family of GitHub, so your home things to use on the line, So mother no longer have to worry about you will not be able to masturbate, the sleeve is dry, young people do not bother! I here is holding someone else's code, but with someone else at least give a star not so stingy, people write code is also very hard right! Don't say much nonsense! Look at my top top!
See there is no status bar height, here you must not forget we have titlebar those, now what to do?
Little friends? How to solve, the general old driver would like to think: "Can give a View to the top of him", the answer is definitely OK!
But I can't think of a rookie like that. The problem is always solved, life still has to go on, so think about it, I still do not know?
Good or bad, simply do not give me out! Good or bad, good or bad!
Try to think about .....
Knock, knock, thump
Well, you seem to have forgotten something? I remember it seems like there's a fixsystemwindow set to true, okay? haha, try it.
But a bit of a problem, some can, some not, and then look at,
Finally add a style
<stylename="Nostatusstyle"Parent="Apptheme"> <Item name="Android:windowtranslucentstatus">true</Item> <!--the status bar is transparent, if set to false, there is no black bar cover, see Contrast- -<Item name="Android:windowtranslucentnavigation">true</Item> <!--the navigation bar is transparent --<Item name="Android:statusbarcolor"> @android: color/holo_green_light</Item> </style>
Then add such attributes to each activity except for those full-screen activity. Here we all know ha!
android:fitsSystemWindows="true" style="@style/NoStatusStyle"
Perfect solution! Let me kiss the earth! Recommended articles:
1. Three ways to implement an Android immersive status bar
2.Android Immersion status bar
write to the end:
Kotlin
>
Good article to learn to share, say today isGoogleioGeneral Assembly, later we may slowly with Catalina elder brother study, temporarily with Java elder brother, departs farewell, this certainly has a section of distance certainly to wait until as perfect compatible to here trample pit basically end, I know everybody also has many other methods. We can leave a message below, I will humbly accept, reprint please indicate the source! Every day with the code in a piece endure loneliness and loneliness, but the hero is doomed to be lonely! I am now a rookie, one day I will become an old driver? Haha joke, whether it is Catalina or Java programming forever endless!
Concluding remarks:
I heard that the people will be good luck will not be too bad don't believe you try!
Android status bar those little pits?