android - 错误自定义搜索建议AppCompat主题

时间:2014-12-25 21:17:50

标签: android search background themes android-appcompat

我尝试自定义AppCompat主题(Base.Theme.AppCompat.Light.DarkActionBar)来更改搜索建议背景颜色和文字。
这是我的样式文件:

<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>

编译后,我收到这种错误:
错误:(24,21)找不到与给定名称匹配的资源:attr&#39; searchViewAutoCompleteTextView&#39;。
错误:(22,21)找不到与给定名称匹配的资源:attr&#39; searchViewCloseIcon&#39;。
错误:(21,21)找不到与给定名称匹配的资源:attr&#39; searchViewSearchIcon&#39;。
错误:(23,21)找不到与给定名称匹配的资源:attr&#39; searchViewTextField&#39;。
有什么建议吗?

2 个答案:

答案 0 :(得分:6)

Hei,自APPCOMPAT V21以来,您应该将代码更改为:

<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>

答案 1 :(得分:0)

代替searchViewTextField,用于样式化searchView EditText在Application主样式中使用android:autoCompleteTextViewStyle

<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>