1

So, I've this menu.xml with the searchView widget:

<item android:id="@+id/action_search"
    android:title="@string/action_search"
    app:showAsAction="ifRoom|collapseActionView"
    app:actionViewClass="android.support.v7.widget.SearchView" />

And I'm trying to style it (queryHint and icon properties) in the styles xml:

<resources>

<!-- Base App Theme -->
<style name="AppTheme" parent="CustomTheme.Base" />

<style name="CustomTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="searchViewStyle">@style/CustomTheme.Base.SearchView</item>
</style>

<style name="CustomTheme.Base.SearchView" parent="Widget.AppCompat.SearchView">
    <item name="searchIcon">@drawable/ic_search</item>
    <item name="queryHint">@string/search_hint</item>
</style>

</resources>

And the result is a searchView widget with no icon and no personalized queryHint... I've been searching on SO and I end up trying this solution, but everytime I try to prefix the searchIcon or queryHint items with my app namespace I get this error on launch:

Error:(26, 21) No resource found that matches the given name: attr 'app:searchIcon'.
Error:(26, 21) No resource found that matches the given name: attr 'app:queryHint '.
Community
  • 1
  • 1
yat0
  • 967
  • 1
  • 13
  • 29
  • Where did you get those attributes? Do they even exist in `Widget.AppCompat.SearchView`? – Jared Burrows Aug 12 '15 at 02:08
  • @JaredBurrows yes they do, it's specified here: http://android-developers.blogspot.pt/2014/10/appcompat-v21-material-design-for-pre.html – yat0 Aug 12 '15 at 02:09
  • That is almost 1 year old. Did you check to see if they exist in `Widget.AppCompat.SearchView`? Things move fast in Android. Also, are you using the latest App Compat? – Jared Burrows Aug 12 '15 at 02:15
  • @JaredBurrows I was checking now and yes, I'm using the latest AppCompat (22.2).. Also, the attribute "searchIcon" doesn't seem to exist anymore, but the queryHint still exists, and I really can't find an answer for what's wrong in my code.. – yat0 Aug 12 '15 at 02:42
  • In all honestly, why change the icon from the default anyways? Stick to the material design. – Jared Burrows Aug 12 '15 at 03:01
  • @JaredBurrows I'll stick to the material design, my icon is the same as the default one, but with no opacity.. Anyway, I don't really mind with this, I can set the icon on the menu.xml.. On the other side, for the queryHint I think I'll go the programmer way, hard coding it on the activity class, at least until I cannot found some documentation for this problem.. – yat0 Aug 12 '15 at 03:07
  • Bruno, simply add your icon to your `menu.xml` where you specify the `app:actionViewClass="android.support.v7.widget.SearchView"` instead. So `android:icon="@drawable/ic_search"`. – Jared Burrows Aug 12 '15 at 11:04
  • That's what I said I was going to do in my previous answer, "Anyway, I don't really mind with this, I can set the icon on the menu.xml..". But thanks anyway for the help @JaredBurrows – yat0 Aug 12 '15 at 12:38

0 Answers0