Implement immersive title bar for android4.4

Source: Internet
Author: User

Implement immersive title bar for android4.4

Check the websites and summarize the two feasible methods based on your time.

1. Modify the style file:

1. Add the values-v19 folder and add the following to styles. xml:

 

 

Ii. Use open-source libraries

1. Add dependencies to android studio:

compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'

 

2. Call the following method in onCreate () of the activity:

 

   /**     * 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(19)    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 using the above two methods, you must add them to the main layout:

 

 

android:fitsSystemWindows="true"

Otherwise, the title bar is white.

 

Related Article

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.