如何将搜索图标的颜色更改为提示

时间:2016-09-29 06:16:38

标签: android android-actionbar android-imageview android-toolbar android-icons

在我的手机中,搜索图标的颜色以灰色显示。

enter image description here

我尝试使用以下代码将其更改为白色,但没有任何反应:

int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
            ImageView searchhintIcon = (ImageView) searchView.findViewById(magId);
            if (null != searchhintIcon) {
                searchhintIcon.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
            }

如何将此搜索提示图标颜色更改为白色?

这是我的themes.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
        <item name="actionModeBackground">@color/cometchat_grey</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#5477B1</item>
        <item name="android:icon">@android:color/transparent</item>
    </style>

</resources>

2 个答案:

答案 0 :(得分:0)

试试这个答案:

没有简单的方法可以将SearchView图标更改为自定义drawable,因为主题属性searchView搜索图标不公开。

但是,我认为你的问题是由错误的主题继承引起的。请使用android:Theme.Holo.Light.DarkActionBar作为主题的基础。然后,操作栏上的默认图标应为浅色

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
...
</style>

答案 1 :(得分:0)

试试这个,

 private void setColor(ImageView imageView) {
        int color = Color.parseColor("#EE3A8C");
        imageView.setColorFilter(color);
    }

    image = (ImageView) findViewById(R.id.image);
    setColor(image);