Share Coding

Tutorials, Problems, Stuffs …

Android status bar background color

To change status bar background color, setup the following in your v21/style.xml, inside your style.
Yes, they are only working after API 21.

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:statusBarColor">@color/bgStatusBar</item>


For API level > 19
In older version, API level 19, cannot change background color on status bar.
But you can setup a ImageView behide it, and make the status bar full transprant.
Write down the following in your v19/style.xml, inside your style.

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">false</item>

In your Activity, add those code at onCreate()

// Lower then API level 19, do nothing
// Change the background image / color of the st
    ViewGroup contentView = (ViewGroup) activity.findViewById(;

    if (contentView.getChildCount() > 1) {

    int res = resources.getIdentifier("status_bar_height", "dimen", "android");
    int height = 0;
    if (res != 0)
        height = resources.getDimensionPixelSize(res);

    ImageView image = new ImageView(activity);
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height)


Moreover, it is suggested to keep the fitsSystemWindows at style or the root layout.
To use adjustResize function to solve keyboard overlap edittext problem, it must be kept.

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

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: