본문 바로가기

Development/Android

[Android] Set programatically color to the status bar in Android.

This posting shows how to set color to the status bar in Android.

 

Status bar is provided by Android System UI and provides information about the system.

It's the red colored area in the picture below.

 

Set the color you want with the folollowing code.

It's not supported in the version that's lower than Lollipop.

public void setStatusBarColor(int color) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return;
    }

    final Window window = getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(color);
}