Amin Azizzadeh
Amin Azizzadeh

Reputation: 490

How to change status bar icons color in Android?

I want to change the color of the status bar icon from white to my own custom color so that it works in all versions. I try the following code but I can not do it. could you help me, please?



The code I used, but this code is not the only solution for APIS + 23 and doesn't work for low API (API 16, API 17 and etc ).

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

enter image description here



The color scheme I want to change.

color #5DD6D6

enter image description here

Upvotes: 3

Views: 10557

Answers (2)

Swapnil Patil
Swapnil Patil

Reputation: 200

in kotlin you can use following lines

// for white color of status bar 
       
 val window = this.window
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window.statusBarColor = ContextCompat.getColor(this, R.color.white)
        WindowCompat.getInsetsController(window, window.decorView).apply {
            isAppearanceLightStatusBars = true
        }


// for other color of status bar  

val window = this.window
  window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
    window.statusBarColor = ContextCompat.getColor(this, R.color.other_color)
    WindowCompat.getInsetsController(window, window.decorView).apply {
        isAppearanceLightStatusBars = false
    }

Upvotes: 0

Dev4Life
Dev4Life

Reputation: 3307

You can't actually change the status bar icon color in android like that. You can still change the status bar color to whatever you want, but for status bar icons, there are only 2 options - Light (white) or Dark (gray).

If you want to use white icons, then simply put <item name="android:windowLightStatusBar">false</item> attribute in your base application theme. For dark icons <item name="android:windowLightStatusBar">true</item>

You can also do it programmatically like mentioned here - https://stackoverflow.com/a/39596725/10357086

Upvotes: 8

Related Questions