I want to change the background color of ActionBar to my own. I do this:

strings.xml added the color I need to actBar - actBar

Created the themes.xml file:

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="backGTheme" parent="Theme.AppCompat.Light"> <item name="android:actionBarStyle">@color/actBar</item> <!-- Support library compatibility --> <item name="actionBarStyle">@color/actBar</item> </style> </resources> 

To the desired Activity I installed this topic

 <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/backGTheme"> 

I go to the application - The background color of the ActionBar not changed + the name of the application is still missing.

What am I doing wrong?

  • four
    About adding color to strings.xml in more detail. - pavlofff

2 answers 2

Well, if an attribute asks for a style, you give it to him and let's:

  <resources> <style name="backGTheme" parent="Theme.AppCompat.Light"> <item name="android:actionBarStyle">@style/MyActionBar</item> </style> <style name="MyActionBar" parent="Base.Widget.AppCompat.Light.ActionBar.Solid"> <item name="android:background">ANY_HEX_COLOR_CODE</item> </style> </resources> 

    ActionBar outdated, use Toolbar instead. To change the color of the standard ActionBar, you just need to tinker with creating an image in a drawable, and for the Toolbar you just need to specify the link to the XML in the Toolbar