How to change the color of Action Bar in an Android App?

Posted by

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

styles.xml

activity_main.xml

MainActivity.java

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

activity_main.xml

Output:

  • Default color of action Bar:
  • In Main Activity color of Action Bar is changed to hash code defined in above code.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x