About immersion status bar I believe everyone is familiar with the iOS system is very early, android5.0 and later versions are supported to the status bar coloring, and the current Android mainstream version is still 4.4, online universal Implementation 4.4 (API19) Immersion status bar is also dependent on the status bar can be changed to transparent properties, and then coloring, the main implementation code:
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_match_actionbar);
Only valid
if (Build.VERSION.SDK_INT >= build.version_codes for api19 above version. KitKat) {
settranslucentstatus (true);
}
Coloring the status bar
systembartintmanager Tintmanager = new Systembartintmanager (this);
Tintmanager.setstatusbartintenabled (true);
Tintmanager.setstatusbartintresource (R.COLOR.STATUSBAR_BG);
}
@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);
}
Then add the following two properties to the root layout:
Android:fitssystemwindows= "true"
android:cliptopadding= "false"
This is OK, the above coloring uses the systembartint.
Why do I have to look for other options?
The face of most of the interface is naturally not much of a problem, but for similar to QQ such as Sideslip interface, as shown:
My mobile phone system version is 4.4, if you want to make the QQ sideslip background such effect, using the above scheme has become such
Such a result will be very ugly, then have an improved version of the scheme, I do not know whether QQ is to do so.
In addition to the above flaws, there is a point that is not very comfortable, is when I use the drawer menu or sliding back to the effect of the time is this
The status bar does not have a shadow effect
The effect I want is this.
The status bar will also slide along
First way of thinking
Customize a status bar, you cannot add "android:fitssystemwindows=" true "
"This property, otherwise cannot be populated to the status bar, as follows
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:layout_width=" match_parent "
android:layout_height=" Match_parent "
android: background= "@color/coloraccent"
android:orientation= "vertical" >
<view android:id=
"@+id/ Status_bar "
android:layout_width=" match_parent "
android:layout_height=" 20DP "/>
<framelayout
android:layout_width= "match_parent"
android:layout_height= "match_parent"/>
</ Linearlayout>
To judge in the code
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
View StatusBar = Findviewbyid (R.id.status_bar);
Setcontentview (r.layout.activity_test);
Determine if the SDK version is greater than or equal to 19, greater than let him show, is less than to hide, otherwise the lower version will be more than one
if (Build.VERSION.SDK_INT >= build.version_codes. KitKat) {
settranslucentstatus (true);
Statusbar.setvisibility (view.visible);
Also set the View height because each model cell phone status bar height is not the same
}else{
statusbar.setvisibility (view.gone);
}
@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);
}
In fact, this has solved the two issues I raised above
The second implementation of the scheme
The second scheme is to solve the first solution of the problems encountered, set the transparent properties of the interface (chat and the box below) can not be the top of the system input method, before writing an Android chat interface background image was input method "on top" problem analysis, Now encountered is no matter what the chat input box can not be the top of the system input method (that is, typing can not see the input box), after a test, found unexpectedly and "android:fitssystemwindows=" true "
"This property, plus go to the input box is OK, but the custom status bar can not be filled to the real status bar position
Caught in a dilemma, add or not all have problems, and are particularly obvious, said a half-day, to see the second option.
<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns: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:background= "@android: Color/holo_green_light" android:fitssystemwindows= "true" tools: context= "Com.saidtx.myapplication.TestActivity" > <scrollview android:layout_width= "match_parent" Android: layout_height= "Match_parent" android:layout_above= "@+id/edit" android:background= "@android: Color/white" > < LinearLayout android:layout_width= "match_parent" android:layout_height= "wrap_content" > <TextView Andro Id:layout_width= "Match_parent" android:layout_height= "wrap_content" android:gravity= "Center" android:padding= " 20DP "android:text=" @string/previews "/> </LinearLayout> </ScrollView> <linearlayout android:i D= "@+id/edit" android:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:layout_alignparentbottom= "true" android:background= "@android: color/ White "> <edittext android:layout_width=" match_parent "android:layout_height=" wrap_content "/> </Linea
Rlayout> </RelativeLayout>
The key is the following two attributes, there is a need to add a background in other child layouts, or follow the outermost background, the code part or the use of the online general scheme, just do not need to customize the status bar, and do not need to calculate the height of the status bar
Android:fitssystemwindows= "true"
android:background= "@android: Color/holo_green_light"
Final effect
The above is the entire content of this article, I hope to learn more about Android software programming help.