Reputation: 773
I'm trying to customize my AppCompat theme (Base.Theme.AppCompat.Light.DarkActionBar) to change search suggestion background color and text.
Here it is my style file:
<resources>
<!-- extend one of the Theme.AppCompat themes -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- customize the color palette -->
<item name="colorPrimary">@color/material_blue_500</item>
<item name="colorPrimaryDark">@color/material_blue_700</item>
<item name="colorAccent">@color/material_blue_200</item>
<item name="android:windowBackground">@color/material_blue_200</item>
<item name="android:actionBarStyle">@style/ActionBar</item>
<item name="android:actionBarWidgetTheme">@style/ActionBarWidget</item>
</style>
<!-- Actionbar Theme -->
<style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/material_blue_200</item>
<item name="android:icon">@drawable/ic_launcher</item>
</style>
<style name="ActionBarWidget" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- SearchView customization-->
<item name="searchViewSearchIcon">@drawable/ic_action_search</item>
<item name="searchViewCloseIcon">@drawable/ic_action_remove</item>
<item name="searchViewTextField">@drawable/ab_textfield_searchview</item>
<item name="searchViewAutoCompleteTextView">@style/AutoCompleteTextView</item>
</style>
<style name="AutoCompleteTextView" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:textColor">@android:color/white</item>
<item name="android:textCursorDrawable">@null</item>
<item name="android:textColorHighlight">@color/material_blue_200</item>
</style>
</resources>
After compilation, I receive this kind of errors:
Error:(24, 21) No resource found that matches the given name: attr 'searchViewAutoCompleteTextView'.
Error:(22, 21) No resource found that matches the given name: attr 'searchViewCloseIcon'.
Error:(21, 21) No resource found that matches the given name: attr 'searchViewSearchIcon'.
Error:(23, 21) No resource found that matches the given name: attr 'searchViewTextField'.
Any suggestion?
Upvotes: 1
Views: 2510
Reputation: 71
Instead of searchViewTextField, for styling searchView EditText use android:autoCompleteTextViewStyle in Application main style
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
....
<item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextView</item>
</style>
<style name="AutoCompleteTextView" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:textColor">@android:color/white</item>
<item name="android:textCursorDrawable">@null</item>
<item name="android:textColorHighlight">@color/search_text_color</item>
</style>
Upvotes: 0
Reputation: 4584
Hei, Since APPCOMPAT V21, you should change your code to this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="searchViewStyle">@style/AppTheme.SearchView</item>
</style>
<style name="AppTheme.SearchView" parent="Widget.AppCompat.SearchView">
<item name="searchIcon">@drawable/your_search_icon</item>
<item name="closeIcon">@drawable/your_close_icon</item>
</style>
Upvotes: 7