4

I am doing an app and the status bar is now white. I'm not doing anything fancy with the layout. How can I get the status bar to show as "normal" (which would be dark with white icons). screen shot.

Here is my layout:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
   android:id="@+id/container_toolbar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   xmlns:android="http://schemas.android.com/apk/res/android">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar" />

 <include layout="@layout/content_movie_detail" />

</LinearLayout>

Toolbar:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:local="http://schemas.android.com/apk/res-auto"
  android:id="@+id/toolbar"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:minHeight="?attr/actionBarSize"
  android:background="@color/colorPrimary"
  local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movie_detail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();

    try {
        assert actionBar != null;
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
    } catch (Exception ignored) {
        Log.e(TAG,ignored.toString());
    }

}

What am I missing?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106

4 Answers4

21

I found the answer here:

Status bar is white

<item name="android:statusBarColor">@android:color/transparent</item>

You'll see that line of code in values/styles/styles.xml(v21) . Remove it and that solves the issue

Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
0

The colour of the status bar depends on the value of colorPrimaryDark which can be found in your styles.xml file.

Alternatively you can set the color like this: setStatusBarColor(). Here you can find more information.

sininen
  • 503
  • 1
  • 6
  • 20
0

There are two ways to set your statusbar color as said before. The first one is changing the colorPrimaryDark on the colors.xml in values folder.

The other way to set the status bar color is programmatically by the Window class:

Android Lollipop brought with it the ability to change the color of status bar in your app for a more immersive user experience and in tune with Google’s Material Design Guidelines. Here is how you can change the color of the status bar using the new window.setStatusBarColor method introduced in API level 21. Changing the color of status bar also requires setting two additional flags on the Window; you need to add the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag and clear the FLAG_TRANSLUCENT_STATUS flag.

Window window = activity.getWindow();

// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

// finally change the color
window.setStatusBarColor(activity.getResources().getColor(R.color.my_statusbar_color));

P.S.: The setStatusBarColor method works on android API 5.0 or above. To change the status bar color from KitKat to above, this block of code will work:

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));
    }

As you can see, it creates a View object and set it backgroundColor.

Refference:

How to change the status bar color in android

http://www.dynamicguru.com/android/change-color-of-status-bar-in-android-apps-programmatically/

Natan Felipe
  • 173
  • 1
  • 5
0

I guess your colorPrimaryDark is white/transparent in style.xml .Change colorPrimaryDark in style.xml file from white to any other color which you want.

Jyoti Sharma
  • 233
  • 1
  • 9