Android Transparent status bar method and its adaptation keyboard push (one)
Source: Internet
Author: User
<span id="Label3"></p><p><p>The Android status bar (statusBar) version is quite different. On Android 4.4 and 5.x you can set the status bar background color, but you can't set the color of words and icons in the status bar. The system default StatusBar font and icon color is White. If you want to implement a transparent status bar below 6.0 (that is, to extend the entire interface to statusbar), you should consider that if your application background color is white, it will appear that the contents of the StatusBar are not clear, this is not a way to Adapt. however, more than 6.0 can modify the background color of the statusbar, or modify the StatusBar font and icon color (only black or white).</p></p><p><p>There are two ways to implement the transparent status Bar:</p></p><p><p>1. Through the toolbar to Achieve. Then configure it in the root xml:<strong>fitsystemwindows</strong> can</p></p><p><p></p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;"><?xml version= "1.0" encoding= "utf-8"? ><android.support.v7.widget.toolbar xmlns:android= "/http Schemas.android.com/apk/res/android " android:id=" @+id/toolbar " android:layout_width=" match_parent " android:layout_height= "wrap_content" android:background= "@color/transparent" android:theme= "@ Style/actionbartheme "/></pre></pre><p><p>The style of Actionbartheme is:</p></p><p><p></p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;"><style name= "actionbartheme" parent= "@style/theme.appcompat.light.noactionbar" > <item name= "android: Textcolorprimary "> @android:color/white</item> <item name=" android:windowtranslucentstatus "tools : targetapi= ">true</item> <item name=" android:windowcontentoverlay "> @null </item> <item name= "windowactionbar" >false</item> <!--Material Theme-- <item name= " Colorprimary "> @color/transparent</item> <item name=" colorprimarydark "> @color/transparent< /item> <item name= "android:statusbarcolor" tools:targetapi= "> @color/transparent</item> <item name= "android:windowdrawssystembarbackgrounds" tools:targetapi= ">true</item> </" Style></pre></pre><p><p>Add in Activity:</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;">GetWindow (). addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)</pre></pre><p><p>however, after this setting, you will find that there is an edit box interface, in the manifest in a timely configuration of adjustresize, the keyboard pop-up, will not push the interface, will cause the keyboard will be overwritten to the edit box (if you apply the edit box closer to the bottom), the experience is not good. At this point, you need to add your own definition of view in this interface, while going to the override Fitsystemwindows method and the Omapplywindowinsets Method.</p></p><p><p></p></p><pre class="brush:java;gutter:true;">public class Softinputadjusttopview extends Relativelayout {private int[] minsets = new int[4]; Public Softinputadjusttopview (context Context) {super (context); } public Softinputadjusttopview (context context, attributeset attrs) {super (context, attrs); } public Softinputadjusttopview (context context, attributeset attrs, int defstyle) {super (context, attrs, defst yle); } @Override protected Final Boolean fitsystemwindows (Rect insets) {if (Build.VERSION.SDK_INT >= build.ver Sion_codes. M) {minsets[0] = insets.left; minsets[1] = insets.top; minsets[2] = insets.right; Insets.left = 0; Insets.top = 0; Insets.right = 0; } return super.fitsystemwindows (insets); } @Override Public final windowinsets onapplywindowinsets (windowinsets insets) {if (Build.VERSION.SDK_INT &G t;= Build.version_codes. M) {minsets[0] = Insets.getsystemwiNdowinsetleft (); minsets[1] = Insets.getsystemwindowinsettop (); minsets[2] = Insets.getsystemwindowinsetright (); return super.onapplywindowinsets (insets.replacesystemwindowinsets (0, 0, 0, INSETS.GETSYSTEMWINDOWINSETB Ottom ())); } else {return insets; } }}</pre><p><p>This will be a good way to implement the adaptation Problem.</p></p><p><p> </p></p><p><p> </p></p><p><p></p></p><p><p>Android Transparent status bar method and its adaptation keyboard push (one)</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service