Android statusbar icons color - android
I was wondering if it's possible to change the statusbar icons colour (not the statusbar colour, colorPrimaryDark)
Let's say I want this statusbar with:
<item name="colorPrimaryDark">#android:color/white</item>
and the icons in black, is it possible?
Thanks.
EDIT:
New in the M developer preview: windowLightStatusBar. Flipping this on
in your theme tells the system to use a dark foreground, useful for
lighter colored status bars. Note the M preview seems to have a bug
where notification icons remain white, while system status icons
correctly change to semitransparent black.
from: Roman Nurik Google+ post
Yes it's possible to change it to gray (no custom colors) but this only works from API 23 and above you only need to add this in your values-v23/styles.xml
<item name="android:windowLightStatusBar">true</item>
#eOnOe has answered how we can change status bar tint through xml. But we can also change it dynamically in code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
View decor = getWindow().getDecorView();
if (shouldChangeStatusBarTintToDark) {
decor.setSystemUiVisibility(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.setSystemUiVisibility(0);
}
}
if you have API level smaller than 23 than you must use it this way.
it worked for me declare this under v21/style.
<item name="colorPrimaryDark" tools:targetApi="23">#color/colorPrimary</item>
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
Not since Lollipop. Starting with Android 5.0, the guidelines say:
Notification icons must be entirely white.
Even if they're not, the system will only consider the alpha channel of your icon, rendering them white
Workaround
The only way to have a coloured icon on Lollipop is to lower your targetSdkVersion to values <21, but I think you would do better to follow the guidelines and use white icons only.
If you still however decide you want colored icons, you could use the DrawableCompat.setTint method from the new v4 support library.
SystemUiVisibility flags are deprecated. Use WindowInsetsController instead
the code below sets the color of icons to black (for the light statusbar)
//icon color -> black
activity.getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS);
and the code below clears it(i.e. turns icon color to white for dark statusbar):
//icon color -> white
activity.getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS);
link to docs :
https://developer.android.com/reference/android/view/WindowInsetsController#setSystemBarsAppearance(int,%20int)
Setting windowLightStatusBar to true not works with Mi phones, some Meizu phones, Blackview phones, WileyFox etc.
I've found such hack for Mi and Meizu devices. This is not a comprehensive solution of this perfomance problem, but maybe it would be useful to somebody.
And I think, it would be better to tell your customer that coloring status bar (for example) white - is not a good idea. instead of using different hacks it would be better to define appropriate colorPrimaryDark according to the guidelines
You can do it programmatically with retaining all other system UI visibility flags.
public static void changeStatusBarContrastStyle(Window window, Boolean lightIcons) {
View decorView = window.getDecorView();
if (lightIcons) {
// Draw light icons on a dark background color
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
// Draw dark icons on a light background color
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
in kotlin you can use following lines
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
}
This is for all those who want to change their application's Notification small icon color can use this setColor method of NotificationCompat.Builder
Example:
val builder = NotificationCompat.Builder(this, "whatever_channel_id")
**.setSmallIcon(R.drawable.ic_notification) //set icon for notification**
.setColor(ContextCompat.getColor(this, R.color.pink))
.setContentTitle("Notification Title")
.setContentText("Notification Message!")
I used two line of code for different status bar color
1st: If status bar color is white then use this line of code to visible the status bar icon:
pingAct.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
2nd: If you use dark color then use this line of code to make visible the status bar icon:
pingAct.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
Yes you can change it. but in api 22 and above, using NotificationCompat.Builder and setColorized(true) :
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, context.getPackageName())
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)
.setLargeIcon(largeIcon)
.setContentIntent(intent)
.setColorized(true)
.setDefaults(0)
.setCategory(Notification.CATEGORY_SERVICE)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_HIGH);
Related
How do I change the color of the icons in the top bar with Android studio? [duplicate]
I was wondering if it's possible to change the statusbar icons colour (not the statusbar colour, colorPrimaryDark) Let's say I want this statusbar with: <item name="colorPrimaryDark">#android:color/white</item> and the icons in black, is it possible? Thanks. EDIT: New in the M developer preview: windowLightStatusBar. Flipping this on in your theme tells the system to use a dark foreground, useful for lighter colored status bars. Note the M preview seems to have a bug where notification icons remain white, while system status icons correctly change to semitransparent black. from: Roman Nurik Google+ post
Yes it's possible to change it to gray (no custom colors) but this only works from API 23 and above you only need to add this in your values-v23/styles.xml <item name="android:windowLightStatusBar">true</item>
#eOnOe has answered how we can change status bar tint through xml. But we can also change it dynamically in code: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { View decor = getWindow().getDecorView(); if (shouldChangeStatusBarTintToDark) { decor.setSystemUiVisibility(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.setSystemUiVisibility(0); } }
if you have API level smaller than 23 than you must use it this way. it worked for me declare this under v21/style. <item name="colorPrimaryDark" tools:targetApi="23">#color/colorPrimary</item> <item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
Not since Lollipop. Starting with Android 5.0, the guidelines say: Notification icons must be entirely white. Even if they're not, the system will only consider the alpha channel of your icon, rendering them white Workaround The only way to have a coloured icon on Lollipop is to lower your targetSdkVersion to values <21, but I think you would do better to follow the guidelines and use white icons only. If you still however decide you want colored icons, you could use the DrawableCompat.setTint method from the new v4 support library.
SystemUiVisibility flags are deprecated. Use WindowInsetsController instead the code below sets the color of icons to black (for the light statusbar) //icon color -> black activity.getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS); and the code below clears it(i.e. turns icon color to white for dark statusbar): //icon color -> white activity.getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS); link to docs : https://developer.android.com/reference/android/view/WindowInsetsController#setSystemBarsAppearance(int,%20int)
Setting windowLightStatusBar to true not works with Mi phones, some Meizu phones, Blackview phones, WileyFox etc. I've found such hack for Mi and Meizu devices. This is not a comprehensive solution of this perfomance problem, but maybe it would be useful to somebody. And I think, it would be better to tell your customer that coloring status bar (for example) white - is not a good idea. instead of using different hacks it would be better to define appropriate colorPrimaryDark according to the guidelines
You can do it programmatically with retaining all other system UI visibility flags. public static void changeStatusBarContrastStyle(Window window, Boolean lightIcons) { View decorView = window.getDecorView(); if (lightIcons) { // Draw light icons on a dark background color decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } else { // Draw dark icons on a light background color decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } }
in kotlin you can use following lines 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 }
This is for all those who want to change their application's Notification small icon color can use this setColor method of NotificationCompat.Builder Example: val builder = NotificationCompat.Builder(this, "whatever_channel_id") **.setSmallIcon(R.drawable.ic_notification) //set icon for notification** .setColor(ContextCompat.getColor(this, R.color.pink)) .setContentTitle("Notification Title") .setContentText("Notification Message!")
I used two line of code for different status bar color 1st: If status bar color is white then use this line of code to visible the status bar icon: pingAct.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); 2nd: If you use dark color then use this line of code to make visible the status bar icon: pingAct.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
Yes you can change it. but in api 22 and above, using NotificationCompat.Builder and setColorized(true) : NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, context.getPackageName()) .setContentTitle(title) .setContentText(message) .setSmallIcon(icon, level) .setLargeIcon(largeIcon) .setContentIntent(intent) .setColorized(true) .setDefaults(0) .setCategory(Notification.CATEGORY_SERVICE) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setPriority(NotificationCompat.PRIORITY_HIGH);
How to change notification background color in android?
how do I change notification color in android? I tried this code but it only changed the title and icon color. NotificationCompat.Builder(mContext,NOTIFICATION_CHANNEL_ID).setColorized(true).setColor(Color.parseColor("#f7da64")
Make sure the Theme/Color used is consistent in application tag of manifest file all style files (style.xml,style.xml(v21)) Make sure in notificationBuilder.setColor(mNotificationColor) , mNotificationColor is really pointing to the expected color code. Check if you are setting meidastyle as shown below .setStyle(new MediaStyle() .setShowActionsInCompactView( new int[]{playPauseButtonPosition})in compact view .setMediaSession(mSessionToken))
Status bar with Android KitKat version fading color?
I want to set the status bar color in Android devices with targetSdkVersion 19 and up. For versions with Lollipop (21) and up, I used this line of code which worked well: getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); to set the status bar color to colorPrimary of my application. However, I noticed that when I try to use this API for SDK version 19 and below, I need to be using version 21. As a result, I looked into it and found How to change the status bar color in android which would solve my problem but when I try to use the following code (Taken from the link above) public static void setTaskBarColored(Activity context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = context.getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //status bar height int statusBarHeight = Utilities.getStatusBarHeight(context); View view = new View(context); view.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); view.getLayoutParams().height = statusBarHeight; ((ViewGroup) w.getDecorView()).addView(view); view.setBackgroundColor(context.getResources().getColor(R.color.colorPrimaryTaskBar)); } } The status bar color is set but it kind of fades from the black to the colorPrimary that I expect it to have. Overall I would want the status bar color to be all colorPrimary instead of fading from black to colorPrimary. Is there any way I can have the status bar to be all colorPrimary for android devices with KitKat downloaded? Or is there a reason why the android KitKat status bar fades from black to the colorPrimary? Either answer would help. Thanks!
As far as I know it's a feature of Android KitKat. Both status bar and navigation bar are always black on the screen edges.
Customize Statusbar - Android
I am creating an application with some Activities. I want to change the status bar color and status bar icon colors which should look like the following image. . Is it possible to change? I am able to change the background color using the following code. if (android.os.Build.VERSION.SDK_INT >= 21) { Window w = getWindow(); // in Activity's onCreate() for instance w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); w.setStatusBarColor(getResources().getColor(R.color.white_background_text)); } Above code is working fine. Now I want to change the Wi-Fi icon, network icon, battery and time. Is it possible to do?
From another answer Yes it's possible to change it to gray (no custom colors) but this only works from API 23 and above you only need to add this in your values-v23/styles.xml <item name="android:windowLightStatusBar">true</item>
Changing notification icon background on Lollipop
I was going through the Notifications design pattern, and didn't find anything that talks about notification icon background. As you probably noticed, there is only a light grey background for custom notifications. But apps like Hangouts, or simply the USB Debugging notification has a custom color for their notification icon background. Is there any possibility to change that grey into something else? (that specific circle's color programmatically)
1) Obtain Color int color = 0xff123456; int color = getResources().getColor(R.color.my_notif_color); int color = ContextCompat.getColor(context, R.color.my_notif_color); 2) Set the Color to the Notification NotificationCompat.Builder builder = new NotificationCompat.Builder(this); ... builder.setColor(color); Notification notif = builder.build(); The color is respected only on Lollipop and only affects background of the small icon. If a large icon is shown its contents are entirely your responsibility. Source: NotificationCompat.Builder#setColor(int)
if you've defined color in colors.xml then in your NotificationBuilder add value as .setColor(getResources().getColor(R.color.<YOUR_COLOR>)) That should solve your problem. It only affect to background of the icon.
getColor(int) has been deprecated on Resources We should now use one of these alternatives: Resources's getColor(int, Theme) ContextCompat's getColor(Context context, int id)