How can I make the status bar white with black icons?
Asked Answered
B

14

108

I want to change the colour of the status bar for my app so that it's white with black icons (instead of the default black with white icons). Is there any way of doing this?

Band answered 23/12, 2014 at 15:47 Comment(11)
Change your default themeDominickdominie
what theme should I change it to that will change the notification bar icons to black?Band
Use custom theme. To start with see #8025206Dominickdominie
so what about apps that follow android guidelines and have white notification icons, how do you expect the user to see them when they are in your app?Instancy
@Instancy That's the question - I want them all to become black and stand out on a white backgroundBand
I though he is talking about the Action bar... :(Dominickdominie
yeah thats not going to happen, your app does not have control of the notification bar let alone other apps resourcesInstancy
no - the notification bar. If it can't be done that's also a legitimate answer.. but if there is a way of doing it then it helps me a lotBand
actually the app can control the color of the bar as of Lollipop - see #22192791Band
edited the question to change the name of the bar to "status bar" (which is what it turns out it's called)Band
but you cannot change the color of other apps resources, in fact lollipop makes all icons white no matter whatInstancy
C
149

With Android M (api level 23) you can achieve this from theme with android:windowLightStatusBar attribute.

Edit :

Just as Pdroid mentioned, this can also be achieved programatically:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); 
Cavin answered 12/8, 2015 at 10:48 Comment(12)
can I set it programmatically?Governess
@Governess I guess you can create a child of your theme and change it there and apply with activity.getTheme.setTo(Theme another)Cavin
Hi @wrecker i have same issue with my application notification icon. I have added android:windowLightStatusBar=true in my theme and i am testing it in Android M. but the white notification icon not changing to grey when i change the theme using a third party launcher application (Nova Launcher) . I have tried all the possible ways but haven't able to fixed it yet . If you can help me it will be grateful .Guncotton
@Guncotton if other app's icons work but yours fail, there could be a problem with your notification iconCavin
@wrecker Thanks for your quick response. I got the solution . There is no issue with my code or with notification icon. I checked it in nexus device it is working fine. Only in few samsung device it is not working .Guncotton
@Governess Yes you can set it at any time by using following method: View.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); It should be added to the answerBumpkin
Is it possible to change the icons color to a custom color (not only black or white)?Miscegenation
@Dahnark as far as I know tinting the icons are not supported, and there is a great chance that they will not allow it for system coherinceCavin
what if i want to use in 22 or previous versions ?Bluetongue
@DharaPatel not possibleCavin
How to do the opposite as now with P and above I can dynamically switch between light and dark themes... I can't find the opposite flag or a clear methodWhoever
@Whoever to revert this, use this value: View.SYSTEM_UI_FLAG_VISIBLE (the default)Aviary
A
65

It is possible to make the white status bar with grey icons e.g. this way for SDK >= 23 (see docs):

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowLightStatusBar">true</item>
</style>

in your styles.xml and set the colorPrimary to white or programmatically:

getWindow().setStatusBarColor(Color.WHITE);
Amphitryon answered 23/10, 2017 at 19:40 Comment(0)
O
16

Just added to my activity on Kotlin:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                window.decorView.systemUiVisibility =View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
                window.statusBarColor = Color.WHITE
            }
Ova answered 1/3, 2018 at 10:55 Comment(0)
F
15

this is what worked for me

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowLightStatusBar">true</item>
    <item name="android:statusBarColor">@android:color/white</item>
</style>
Forkey answered 19/1, 2021 at 13:16 Comment(2)
this requires minimum Api level 23Scintilla
@Scintilla probably. I don't support anything below api 24 in any of my apps.Forkey
L
10

just add this to you style

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>

set android:windowDrawsSystemBarBackgrounds to true*. This is a flag whose description is given below:

Flag indicating whether this Window is responsible for drawing the background for the system bars. If true and the window is not floating, the system bars are drawn with a transparent background and the corresponding areas in this window are filled with the colors specified in {@link android.R.attr#statusBarColor} and {@link android.R.attr#navigationBarColor}. Corresponds to {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS}.

Lyndseylyndsie answered 20/8, 2018 at 20:47 Comment(0)
T
3

You can use it this way in Kotlin

 window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

Make sure to call it in onCreate() before setContentView()

Trilley answered 3/3, 2020 at 16:43 Comment(0)
N
3
 In your app theme use color for status bar like this 
 <style name="Theme.YourAppName" 
    parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/statusBar</item>
    <item name="statusBarBackground">@color/statusBar</item>
    <item name="colorOnPrimary">@color/white</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/teal_200</item>
    <item name="colorSecondaryVariant">@color/teal_700</item>
    <item name="colorOnSecondary">@color/black</item>
    <!-- Status bar color. -->


    <item name="android:statusBarColor" tools:targetApi="l">? attr/statusBarBackground</item>

 use this code for icon change color
    <item name="android:windowLightStatusBar">true</item>
    <!-- Customize your theme here. -->
</style>
Neckpiece answered 22/7, 2022 at 6:47 Comment(0)
C
2

one of the best solutions you can use:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            val decor = this.window.decorView
            // valu reflected to set status bar icons in black
            if (value) {
                decor.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            } else {
                // We want to change tint color to white again.
                // You can also record the flags in advance so that you can turn UI back completely if
                // you have set other flags before, such as translucent or full screen.
                decor.systemUiVisibility = 0
            }
        }

this code is inspired by this comment https://mcmap.net/q/75604/-android-statusbar-icons-color

Cogitation answered 22/9, 2021 at 14:21 Comment(0)
S
2

There are two approaches we can take.

1. Dynamically:

fun Activity.setStatusBarColorAndAppearance(statusBarColor: String, isLight: Boolean ) {
    try {
        window.statusBarColor = (Color.parseColor(statusBarColor))// Or we can use from resource color:  ContextCompat.getColor(mContext, R.color.colorPrimary)
        WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightStatusBars = isLight
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

And use it inside the onCreate() method:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setStatusBarColorAndAppearance("#5e5c64", false)

    ....

}

2. By xml:

Use this in AppTheme

<item name="android:windowLightStatusBar">false</item>
<item name="android:statusBarColor">@color/colorPrimary</item>

Note: Tested above 8.0.

Subsequence answered 9/11, 2022 at 13:7 Comment(2)
How can an exception be thrown here? Is there a reason why you put a try catch around the code?Oligocene
@EhsanMashhadi I got an exception in some case. So I put it into try catch. I am not sure but the exception was regarding Android 13 GO edition.Subsequence
A
1

I just used this

  1. Set the parent in style
parent="Theme.AppCompat.Light.NoActionBar"
  1. Add this to the menu bar in xml
  app:theme="@style/AppThemeWithoutActionBarwithwhitehed"       
  android:background="#fff"
Applique answered 20/12, 2020 at 21:49 Comment(0)
S
0

No such way to this unless if you have a control of the whole rom to customize that manually. What i suggest you to do is, use a light gray color for the status bar color through your theme like the google drive does.

Edit: please refer to @Wrekcker answer as this changed in android M.

Suburb answered 23/12, 2014 at 16:21 Comment(1)
It's supported in Android MFrimaire
R
0

I achieved it using:

  if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
        setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, true);
    }
    if (Build.VERSION.SDK_INT >= 19) {
        setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false);     }

    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        getWindow().setStatusBarColor(Color.WHITE);
    }



setContentView(R.layout.activity_mainss);

Theme is set in AndroidManifest:

 <style name="Theme.MapRiti" parent="Theme.AppCompat.DayNight.DarkActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/purple_500</item>
    <item name="colorPrimaryDark">@color/orange</item>
    <item name="colorPrimaryVariant">@color/purple_700</item>
    <item name="colorSecondary">@color/teal_200</item>
    <item name="colorSecondaryVariant">@color/teal_700</item>
</style>
Renegado answered 10/6, 2021 at 17:1 Comment(0)
N
0

In your app theme use color for status bar like this @color/statusBar color is in color file ?attr/statusBarBackground this code is for setting status bar color automatically when light mode flag is called..

true and this code of flag is for changing the icon's color to dark when light mode flag is called

this thing worked for me

Neckpiece answered 22/7, 2022 at 6:10 Comment(0)
J
-2

I had the same issue.

I noticed that when I use normal layout like RelativeLayout it doesn't work. But when I switched to that come from support library like CordinatorLayout it has finally started to work. Try this.

  <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".Activities.Activity">


        <android.support.v7.widget.Toolbar
            android:id="@+id/tb_activity"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />


    </android.support.design.widget.CoordinatorLayout>

<********* BELOW OTHERS ATTRIBUTES ************>

styles

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

And in the manifest

<activity
            android:name=".Activities.MyActivity"
            android:label="Activity"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>
Jenny answered 22/3, 2016 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.