Android Implementation Color Status bar

Source: Internet
Author: User

First we need to understand what is transparent status bar and what is the immersion status bar, and its difference, domestic custom says the transparent status bar is an immersive status bar, but the two are essentially different.

Let's take a look at what is immersive mode.

In Android 4.4, the immersive experience has been re-hardened to provide a "full-screen mode" (Full-screen Immersive mode). The full-screen mode is divided into two kinds, one called the Retreat (Lean back), the other is called immersion (Immersive). The retreat has been used extensively in previous systems-when you watch videos in the Youku app, your fingers don't touch the screen most of the time. In this case, the virtual keys and the status bar will be automatically hidden, but they will appear when you touch the screen. And the new immersion is not the same, in the immersive full-screen state, the operation of the screen will not call out the system bar. To call out the system bar, you must enter the screen from the top/bottom edge of the screen. Immersive full-screen status is more suitable for gaming and reading applications.

The difference between immersion mode and normal full screen is that immersive mode can bring up virtual keys and status bar by sliding above or below the screen.
For example, read more, it is full screen in immersion mode when reading.

Then swipe down from the top of the screen or below, and the virtual keys and status bar appear. But it is directly covered in the program text.

And the source of the immersive status bar is a lot of mobile phone with the entity keys, no virtual keys, so open immersion mode only the status bar disappears. Immersive mode becomes an immersive status bar.

Android 4.4 A very important change is the transparent system bar. The new system bar is progressively transparent, allowing the screen to be displayed to the fullest extent possible, or by combining the system bar with the action Bar, leaving only minimal background protection from notifying the notification bar of the contents and Action Bar text/icon is difficult to identify. Google calls this effect: translucent Bar.

Translucent Bar is one of Android's attempts at edge to edge and is the easiest to be noticed by users. Its initial purpose is to maximize the visible area and fade the presence of the system interface.

In fact, the simple point is that the layout extends to the status bar, the status bar background is the same as the application background, this is the transparent status bar *. The most straightforward example is the UC browser's weather interface, whose layout extends to the status bar, but the status bar is the same as the application background,

But this sometimes makes the status bar color the same as the applied background color, but actually just modifies the color of the status bar, which we call a color- changing status bar

And now we are in use of QQ and other software, the status bar and software color into one, in fact, is the color status bar. And Xiaomi Miui's own application, is also a color-changing status bar or transparent status bar, rather than an immersive status bar.

Here we would like to say that the color status bar is a transparent status bar, this article is to bring you to achieve this transparent status bar.

Since this effect is only valid at 4.4 and above, the effect of this article is only valid at 4.4 and above.

Apply a theme First

<resources>    <style name="Apptheme" parent="@style/basetheme">    </style>    <style name= "basetheme" parent=" Theme.AppCompat.Light.NoActionBar "><item name= "colorprimary" >@color/colorprimary</item> <item name="Colorprimarydark"> @color/colorprimarydark</item> </style></Resources>

Then we create a new values-v19 directory under Res, representing a minimum API of 19, creating a new Style.xml, the following code is the key to the transparent status bar

<resources> <style name="AppTheme" parent="@style/BaseTheme"> <item name="android:windowTranslucentNavigation">true</item> <item name="android:windowTranslucentStatus">true</item> </style></resources>

We have disabled the system Actionbar, using toolbar instead, the layout code is as follows

<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"Android:layout_width="Match_parent"android:layout_height="Match_parent"android:orientation="Vertical"> <android. Support. V7. Widgets. ToolbarAndroid:id="@+id/toolbar"Android:layout_width="Match_parent"android:layout_height="Wrap_content"Android:background="? Attr/colorprimary"Android:fitssystemwindows="true"></android. Support. V7. Widgets. Toolbar></LinearLayout>

Careful you will find that the android:fitssystemwindows= "true" attribute is added to the toolbar, which is to extend the layout to the status bar, and when you run it, you will find the toolbar move to the status bar. The height of the move up is exactly the height of the status bar.

But we do not want it to move to the top, just want it the status bar and toolbar color, how to do, very simple, in the code through the setsupportactionbar set to Actionbar location.

Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(mToolbar);

That's how it works after that.

Obviously, toolbar is the height of the previous, but the status bar is also discolored.

But how can we be content with this? On Android 5.0, the color of our status bar is darker than the color of toolbar. Just like this.

We also need to further modify the status bar needs to be colored, here need to use an open source library Systembartint

Join the dependency

  ‘com.readystatesoftware.systembartint:systembartint:1.0.3‘

After you set the layout, add the following code

SystemBarTintManager tintManager=new SystemBarTintManager(this);tintManager.setStatusBarTintResource(R.color.colorPrimaryDark);tintManager.setStatusBarTintEnabled(true);

The final effect is shown

Of course, there are many functions in this library, the specific function to think about it, and its internal source code is not complex, suggest or look at its source code implementation.

The source code of this article is simple, not on the source.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Implementation Color Status 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.