Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lollipop Set Status Bar Text Color

I'm trying to set the status bar text color in Android v21, but I'm not seeing an API method for it. Here's what I have so far for the background

MyActivity.java > onCreate:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {         Window window = getWindow();         window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);          window.setStatusBarColor(getResources().getColor(R.color.white));      } 

Obviously white text on white background won't work. I'm looking for something like

window.setStatusBarTextColor(getResources().getColor(R.color.orange)); 
like image 637
Kristof Avatar asked May 26 '15 16:05

Kristof


People also ask

How can I change the color of my status bar text 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. Step 3: In your MainActivity, add this code in your onCreate method.

Can you change the color of your notification bar on Android?

Probably the best option for non-rooted (and also rooted users, if you enjoy simplicity), Material Notification Panel allows you to completely customize the notification panel with colors, transparency, background photos, and icon style – if you have a Nougat phone but want Oreo notification panel icons, for example, ...

How can I change my status bar in Android?

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 do I change the color of my activity bar?

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


2 Answers

You can not set the status bar text color by specifying any color explicitly

But you can try below alternative which is Added in API 23,

You can use "android:windowLightStatusBar" attribute in two ways

  • "android:windowLightStatusBar" = true, status bar text color will be compatible (grey) when status bar color is light
  • "android:windowLightStatusBar" = false, status bar text color will be compatible (white) when status bar color is dark
<style name="statusBarStyle" parent="@android:style/Theme.DeviceDefault.Light">         <item name="android:statusBarColor">@color/status_bar_color</item>         <item name="android:windowLightStatusBar">false</item> </style> 

You can check above api in below link - https://developer.android.com/reference/android/R.attr.html#windowLightStatusBar

like image 118
Sunita Avatar answered Sep 17 '22 15:09

Sunita


Here's a Java implementation of Gandalf458's answer.

/** Changes the System Bar Theme. */ @RequiresApi(api = Build.VERSION_CODES.M) public static final void setSystemBarTheme(final Activity pActivity, final boolean pIsDark) {     // Fetch the current flags.     final int lFlags = pActivity.getWindow().getDecorView().getSystemUiVisibility();     // Update the SystemUiVisibility dependening on whether we want a Light or Dark theme.     pActivity.getWindow().getDecorView().setSystemUiVisibility(pIsDark ? (lFlags & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) : (lFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)); } 
like image 22
Mapsy Avatar answered Sep 19 '22 15:09

Mapsy