0

I am trying to change the color of my action bar in android studio. I have already changed the minSDKVersion to 21 so I know that is not the problem. Yet I keep getting the error, I don't know what is going on. Here is my xml:

<!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/my_action_bar_color</item>
    <item name="android:navigationBarColor">@color/my_action_bar_color</item>
</style>

No resource found that matches the given name: attr 'colorPrimary'.

ChristianCuevas
  • 2,672
  • 3
  • 19
  • 24

1 Answers1

7

Use android:colorPrimary. colorPrimary on its own will only work if you are inheriting from Theme.AppCompat.

So, for example, in this sample project, I have:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Apptheme" parent="android:Theme.Material">
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/accent</item>
  </style>
</resources>
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So i did that, but the action bar is still grey instead of the color I wanted. – ChristianCuevas Dec 22 '14 at 21:57
  • @AlexFritz: Are you testing on Android 5.0+? What is `@color/my_action_bar_color`? What other differences do you see between what you have and my sample (which is pretty much just "hello, world" with a tinted action bar)? – CommonsWare Dec 22 '14 at 21:59
  • Android 5.0+ yes. It is a red color, #F44336. I tried your exact xml, but I replaced all of them with my_action_bar_color, just to see if anything would change and nothing did. – ChristianCuevas Dec 22 '14 at 22:07
  • @AlexFritz: Are you sure that you are referencing your custom theme in your manifest? – CommonsWare Dec 22 '14 at 22:19
  • This line is in my manifest. android:theme="@style/AppTheme" > I changed the style to name="AppTheme". – ChristianCuevas Dec 22 '14 at 22:24
  • @AlexFritz: Try running my sample project. If you get similar problems, the issue lies with how you are testing. If my project works, perhaps you can figure out what's different. – CommonsWare Dec 22 '14 at 22:29
  • @CommonsWare Do you also have any sample projects for the AppCompat `SearchView`? I am using the "SearchView" section in [this blogpost](http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html) to customize my SearchView but it is not working for me. I'll be thankful if you can point me to any sample project (if available ofcourse). Thank you. – Solace Aug 12 '15 at 19:16
  • @Solace: Well, [here is an `appcompat-v7` `SearchView` sample app](https://github.com/commonsguy/cw-omnibus/tree/master/AppCompat/SearchView), though I have not customized the `SearchView` itself much. If you have further questions on the subject, please ask a fresh Stack Overflow question. – CommonsWare Aug 12 '15 at 19:17
  • @CommonsWare Actually I did [here and also linked to an SSCCE project I posted online](http://stackoverflow.com/questions/31912840/why-dont-appcompat-v21-searchview-styles-work-in-my-app) but nobody answered it. =s – Solace Aug 12 '15 at 19:20