Skip to content

Android status bar color change | android:colorPrimaryDark

  • by

Changing the Android status bar color is very easy in Android Studio. Set color on android:colorPrimaryDark the attribute of the style you’re using for your app in styles.xml.

Android 5.0 Lollipop introduced Material Design theme which automatically colors the status bar based on the colorPrimaryDark value of the theme.


<color name="colorPrimaryDark">#2196F3</color>

On API level 21+ you can also use the Window.setStatusBarColor() method from code.

You can use this simple code in Kotlin:

window.statusBarColor = ContextCompat.getColor(this, R.color.colorName)

Let’s build an Android status bar color change application

Step 1. Create an android project in the android studio (Follow this tutorial: Android First Program in Android Studio).

Step 2. Open the color.xml file.

Step 3. Add your color in the color.xml file.

You can add status bar color in 2 ways, First clicking on left side color box-> it will open a color selector.

Another way direct write a color hex code.

Android status bar color change

Step 4. Now Run the application, in an emulator or on your Android device.

Output screenshot Android android:colorPrimaryDark example:

Android colorPrimaryDark example output

Download Link and Source of Android status bar color change code in Github

Q: How to change Action Bar and Status Bar color in Activity?

Answer: If you want to change the color of my action bar and status bar programmatically only on one activity. Then use this Java(for Kotlin you just copy past and chose change to Kotlin) code.

import android.os.Build;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {


    public void changeColor(int resourseColor) {
            getWindow().setStatusBarColor(ContextCompat.getColor(getApplicationContext(), resourseColor));

        ActionBar bar = getSupportActionBar();
        bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(resourseColor)));



Do comment if you have any doubts and suggestions on this tutorial.

Note: This example (Project) is developed in Android Studio 3.3.2. Tested on Android 9 ( Android-P), compile SDK version API 28: Android 9.0 (Pie)
TargetSdkVersion=28″Coding in Kotlin

Leave a Reply

Your email address will not be published. Required fields are marked *