Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the status bar notification icons' color/tint in android (marshmallow and above 23+)?

Tags:

As the title says, how do I change the status bar icons' color to have a dark tint instead of the default white.

FROM

enter image description here

TO

dark status bar

like image 783
Sazid Avatar asked Oct 24 '15 09:10

Sazid


People also ask

How can I change the color of my status bar in 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.


2 Answers

For the status bar icons' to have a dark tint instead of the default white, add the following tag in your styles.xml (or more precisely in values-v23/styles.xml) file:

<item name="android:windowLightStatusBar" tools:targetApi="23">true</item> 

You can also change the flag at runtime by setting it to any View:

View yourView = findViewById(R.id.your_view);  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {     if (yourView != null) {         yourView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);     } } 

If you want to reset the changes, clear the flag like this:

yourView.setSystemUiVisibility(0); 
like image 98
Sazid Avatar answered Oct 03 '22 01:10

Sazid


Below is sample code, change status bar color when switch between portrait&landscapse. portrait mode : light bar, dark icon; landscape mode : dark bar, light icon; Theme: "Theme.AppCompat.Light"

    @Override     public void onConfigurationChanged(Configuration newConfig) {         super.onConfigurationChanged(newConfig);         Window window = getWindow();         View decorView = window.getDecorView();         if(Configuration.ORIENTATION_LANDSCAPE == newConfig.orientation) {             decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE                     | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION                     | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN                     | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION                     | View.SYSTEM_UI_FLAG_FULLSCREEN                     | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {                 window.setStatusBarColor(Color.parseColor("#55000000")); // set dark color, the icon will auto change light             }         } else {             decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {                 window.setStatusBarColor(Color.parseColor("#fffafafa"));             }         }     } 
like image 25
Jian Li Avatar answered Oct 03 '22 02:10

Jian Li