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.