Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change status bar color to match app in Lollipop? [Android]

In the new lollipop update I noticed that with the native Google apps the color of the status bar changes to match the action bar on the app you're running. I see it's on the Twitter app also so I'm guessing it's not exclusively Google who can do it.

Does anyone know how to do this if it is possible?

like image 943
Briscoooe Avatar asked Nov 23 '14 19:11

Briscoooe


People also ask

Can you change the color of the status bar android?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar.

How can I customize my Android status bar?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.

How can I change the color of my menu bar in Android?

Just go to res/values/styles.edit the xml file to change the color of action bar.


2 Answers

To change status bar color use setStatusBarColor(int color). According the javadoc, we also need set some flags on the window.

Working snippet of code:

Window window = activity.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(ContextCompat.getColor(activity, R.color.example_color)); 


Keep in mind according Material Design guidelines status bar color and action bar color should be different:

  • ActionBar should use primary 500 color
  • StatusBar should use primary 700 color

Look at the screenshot below:

enter image description here

like image 163
klimat Avatar answered Sep 18 '22 00:09

klimat


Just add this in you styles.xml. The colorPrimary is for the action bar and the colorPrimaryDark is for the status bar.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">     <item name="android:colorPrimary">@color/primary</item>     <item name="android:colorPrimaryDark">@color/primary_dark</item> </style> 

This picture from developer android explains more about color pallete. You can read more on this link.

enter image description here

like image 25
Gjoko Bozhinov Avatar answered Sep 20 '22 00:09

Gjoko Bozhinov