Implement android4.4 immersive title bar

Source: Internet
Author: User

Check the major websites, finally combined with their own time, summed up two feasible methods

A. Modify the style file:

1. Add the Values-v19 folder, and then add the styles.xml to it:

<!--Base Application theme. --    <style name= "Apptheme" parent= "Theme.AppCompat.Light.NoActionBar" >        <!-- Toolbar (Actionbar) Color--        <item name= "colorprimary" > @color/colorprimary</item>        <!-- Status bar Color        -<item name= "Colorprimarydark" > @color/colorprimary</item>        <!--toolbar title color-- >        <item name= "android:textcolorprimary" > @color/white</item>        <!--window background color        -- <item name= "Android:windowbackground" > @color/colorprimary</item>        <!--translucent system bars-- >        <item name= "Android:windowtranslucentstatus" >true</item>        <item name= "Android: Windowtranslucentnavigation ">true</item>    </style>

Two. Using the Open Source Library

Add dependencies in 1.android Studio:

'com.readystatesoftware.systembartint:systembartint:1.0.3'

2. Call the following method in the activity's OnCreate ():

   /** * Apply KitKat specific translucency.        */private void applykitkattranslucency () {//KitKat translucent Navigation/status bar. if (Build.VERSION.SDK_INT >= build.version_codes.            KITKAT) {Settranslucentstatus (true);            Systembartintmanager Mtintmanager = new Systembartintmanager (this);            Mtintmanager.setstatusbartintenabled (TRUE);            Mtintmanager.setnavigationbartintenabled (TRUE);            Mtintmanager.settintcolor (0xf00099cc);        Mtintmanager.settintdrawable (uielementshelper. Getgeneralactionbarbackground (this));        }} @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); }

At the end of the two methods above, add the following in the main layout:

Android:fitssystemwindows= "true"

Otherwise the title bar is white.

Implement android4.4 immersive title bar

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.