Can I change status bar colour like this in my app?
Asked
Active
Viewed 244 times
-7
-
2[1](https://stackoverflow.com/questions/42313382/transparent-status-bar-in-android) [2](https://stackoverflow.com/questions/29311078/android-completely-transparent-status-bar) [3](https://stackoverflow.com/questions/41622957/translucent-status-bar-and-toolbar) [4](https://stackoverflow.com/questions/29907615/android-transparent-status-bar-and-actionbar) – denvercoder9 Mar 02 '18 at 10:35
-
`I've seven years of android exp`. Tbh, if you had you wouldn't be asking this question. `Do not show your foolishness in public`. Cut the personal remarks. `How can you say I've not made any attempt?` You haven't shown any of your attempts. I'll not be replying to any of your comments in this thread. Good luck with your project – denvercoder9 Mar 03 '18 at 13:19
2 Answers
0
Yes, you can change it's color, but I am not sure if changing it to transparent will have the effect you want
public static void setStatusBarColor(Activity activity, int color){
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(activity, color));
}

Ionut J. Bejan
- 734
- 11
- 28
0
You can do it by this-:
private void changeStatusBarColor() {
Window window = this.getWindow();
// clear FLAG_TRANSLUCENT_STATUS flag:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
// finally change the color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
}
}

Shivam Oberoi
- 1,447
- 1
- 9
- 18