Android Material: Status bar color won't change Android Material: Status bar color won't change android android

Android Material: Status bar color won't change


The status bar is a system window owned by the operating system. On pre-5.0 Android devices, applications do not have permission to alter its color, so this is not something that the AppCompat library can support for older platform versions. The best AppCompat can do is provide support for coloring the ActionBar and other common UI widgets within the application.


While colouring the status bar is not supported <5.0, on 4.4 you can use a work around to achieve a darker colour:

Make the status bar translucent

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

Then use AppCompat's Toolbar for your appbar, making sure that it fits system windows:

<android.support.v7.widget.Toolbar    android:id="@+id/toolbar"    ...    android:fitsSystemWindows="true"/>

Make sure to set your toolbar as your activity's toolbar:

protected void onCreate(final Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    ...    toolbar = (Toolbar) findViewById(R.id.toolbar);    setSupportActionBar(toolbar);

The toolbar stretches underneath the status bar, and the semi translucency of the status bar makes it appear to be a darker secondary colour. If that's not the colour you want, this combination allows you to fit a view underneath your status bar sporting the background colour of your choice (though it's still tinted darker by the status bar).

Kind of an edge case workaround due to 4.4 only, but there ya go.


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);    getWindow().setStatusBarColor(getResources().getColor(R.color.actionbar));}

Put this code in your Activity's onCreate method. This helped me.