How to change the color of Action Bar in an Android App? (original) (raw)

Last Updated : 12 Jul, 2025

Customizing the Action Bar allows you to enhance the visual appeal of your Android app. In this article, you will learn how to change the colour of the Action Bar in an Android App.

Basically, there are two ways to change color.

  1. **By changing styles.xml file:
    • Just go to **res/values/styles.xml file
    • edit the xml file to change the color of action bar.
    • Code for styles.xml is given below
      MainActivity.java package com.geeksforgeeks.changecolor; import android.widget.TextView; import android.support.v7.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Define text View TextView t = findViewById(R.id.textview); t.setText("Geeks for Geeks"); } } styles.xml ` ` activity\_main.xml `
` 2. ****Through Java file by defining ActionBar object:** * Define object for ActionBar and colorDrawable class * set color using setBackgroundDrawable function with colorDrawable object as its parameter. * Here is complete code for MainActivity.java MainActivity.java ` package com.geeksforgeeks.changecolor; import android.support.v7.app.ActionBar; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.support.v7.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Define ActionBar object ActionBar actionBar; actionBar = getSupportActionBar(); // Define ColorDrawable object and parse color // using parseColor method // with color hash code as its parameter ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#0F9D58")); // Set BackgroundDrawable actionBar.setBackgroundDrawable(colorDrawable); } } ` activity\_main.xml ` `

**Output: