如何在操作栏中更改searchview的图标颜色? [英] How can i change the icon color of searchview in actionbar?

查看:78
本文介绍了如何在操作栏中更改searchview的图标颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">


<item
    android:id="@+id/action_search"
    android:icon="@drawable/search_icon"
    android:title="@string/action_search"
    app:actionViewClass="android.widget.SearchView"
    app:showAsAction="always" />

<item
    android:id="@+id/action_favorite"
    android:icon="@drawable/favorite_icon"
    android:title="@string/action_favorite"
    app:showAsAction="always" />


<item
    android:id="@+id/themes"
    android:title="@string/overflow_menu_item"
    app:showAsAction="never">

<menu>
        <item
            android:id="@+id/background1"
            android:title="Red-PinkGradient"
            />
        <item
            android:id="@+id/background2"
            android:title="Red-Gradient"
            />
        <item
            android:id="@+id/background3"
            android:title="Green-Gradient"
            />
        <item
            android:id="@+id/background4"
            android:title="Black-GreyGradient"
            />
</menu>

</item>

<item
    android:title="@string/overflow_menu_item2"
    android:id="@+id/settings"
    />

这是我的styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="actionOverflowButtonStyle">@style/overFlow</item>
    <item name="searchViewStyle">@style/CustomSearchViewStyle</item>

</style>
<style name="overFlow" parent="@style/Widget.AppCompat.Light.ActionButton.Overflow">
    <item name="android:src">@drawable/ic_overflow_icon</item>
</style>
<style name="CustomSearchViewStyle" parent="Widget.AppCompat.SearchView">
    <item name="queryBackground">@color/white</item>
    <item name="searchIcon">@drawable/search_icon</item>
</style>

如何更改搜索视图的图标颜色? 我试图将项目中的图标设置为可绘制对象,这是一个白色的搜索图标,但我保持黑色. https://imgur.com/a/LCRzt (这是我现在拥有的内容,但是要进行搜索图标必须为白色) https://imgur.com/a/Q65lS (结果是什么)

How can i change the icon color of my searchview? I tried to set the icon in my item to the drawable which is a white search icon, but i stays black. https://imgur.com/a/LCRzt (this is what i have now, but the search icon needs to be white) https://imgur.com/a/Q65lS (what is want as result)

对于其他图标,我希望颜色为白色,但对于搜索视图,我不希望.

I want the color to be white, for the other icons it works, but not for my searchview.

第二个问题是,当我单击搜索图标时,我想要的溢出消失了,但是我最喜欢的图标停留在那儿,我如何使其消失? 以及如何使关闭按钮也变为白色(小的x图标)以关闭searchView. https://imgur.com/a/3EBa4 (我现在所拥有的) https://imgur.com/a/CbvqR (我想要什么) 我该如何解决?

A second problem is when i click the search icon, my overflow disappears which is what i want, but my favorite icon stays there, how can i make it disappear? And how can i make the close button also white, the small x icon to close the searchView. https://imgur.com/a/3EBa4 (what i have now) https://imgur.com/a/CbvqR (what i want) How can i solve this?

预先感谢, -文斯

推荐答案

您需要使用android.support.v7.widget.SearchView

You need to use android.support.v7.widget.SearchView

<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
    <!-- Gets rid of the search icon -->
    <item name="searchIcon">@drawable/ic_search</item>
    <!-- Gets rid of the "underline" in the text -->
    <item name="queryBackground">@color/white</item>
    <!-- Gets rid of the search icon when the SearchView is expanded -->
    <item name="searchHintIcon">@null</item>
    <!-- The hint text that appears when the user has not typed anything -->
    <item name="queryHint">@string/search_hint</item>
</style>

这篇关于如何在操作栏中更改searchview的图标颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆