1

在我的手機中,搜索圖標的顏色以灰色顯示。如何更改搜索圖標的顏色作爲提示

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

試試我的答案。讓我知道它是否適合你? –

+0

什麼是您的圖標的實際顏色? – AbhayBohra

+0

@DaminiMehra我會讓你知道 –

回答

0

嘗試這樣的回答:

有沒有簡單的方法來改變搜索查看圖標,自定義繪製的,因爲主題屬性搜索查看搜索圖標不公開。

但是,我認爲你的問題是由錯誤的主題繼承引起的。請使用android:Theme.Holo.Light.DarkActionBar作爲主題的基礎。然後,操作欄上的默認圖標應該有一個淺色

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

我試過你的解決方案,但仍然面臨這個問題。僅供參考我在Android 4.4.4和較低的API水平面臨這個問題。在Kitkat上方顯示白色圖標。此外,我嘗試更改主應用程序主題中的圖標,但仍然沒有幫助。 –

+0

我們已經添加了themes.xml文件,請檢查 –

+0

我在Kitkat中遇到同樣的問題。但是在棉花糖中沒問題。任何解決方案 – stenlytw

0

試試這個,

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

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

這不是我要找的東西。初始化'圖像'對象時,我怎麼知道'溢出菜單圖標'的'id'? –