Daniel Beltrami
Daniel Beltrami

Reputation: 776

Change StatusBar to White

I'm trying to change the status bar color to white just on one activity, but the icons barely apear:

enter image description here

I'm using this code:

 Window window = getWindow();
 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
 window.setStatusBarColor(Color.TRANSPARENT);

I can't change the ColorPrimaryDark, because I already set one color for all app.

Thanks in advance.

EDIT

I was commenting on a beginner error. This have a very simple solution, that is just set a theme for this activity on manifest file:

android:theme="@style/Theme.AppCompat.Light.NoActionBar"

And this java code on my Activity, as @shahab said:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getWindow();
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    window.setStatusBarColor(Color.TRANSPARENT);
}

Upvotes: 0

Views: 1121

Answers (3)

yousif waleed
yousif waleed

Reputation: 1

Window window = getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    window.setStatusBarColor(Color.TRANSPARENT);
}

else {
    window.setStatusBarColor(Color.WHITE);
}

Upvotes: 0

mostafa3dmax
mostafa3dmax

Reputation: 1017

Use this in onCreate() method :

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

This works from API 23+.

Upvotes: 2

codegames
codegames

Reputation: 1921

changing status bar color is available just for android above lollipop

1.you can change status bar color programmatically by this line:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().setStatusBarColor(ContextCompat.getColor(context, R.color.your_color));
}

2.you can do this with an smooth transition animation:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    int startColor = getWindow().getStatusBarColor();
    int endColor = ContextCompat.getColor(context, R.color.your_color);
    ObjectAnimator.ofArgb(getWindow(), "statusBarColor", startColor, endColor).start();
}

3.or you can add this to your theme style in values/styles.xml file. item colorPrimaryDark will be used for your app status bar color

<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

but for changing status bar icon color to dark you can use SYSTEM_UI_FLAG_LIGHT_STATUS_BAR flag that is available for android above M

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}

or add it to your theme style xml:

<item name="android:windowLightStatusBar">true</item>

Upvotes: 4

Related Questions