vnimmanapalli vnimmanapalli - 2 months ago 29
Android Question

android serach view icon color changing programmatically

How do I change the Android search view icon color? By default color is white, is it possible to change the icon color.

I have tried:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >

<item
android:id="@+id/action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="@drawable/ic_theme_blue_menu"
android:showAsAction="always"
android:title="@string/search_actionbar"/>
<item
android:id="@+id/slider_menu"
android:icon="@drawable/ic_slider_menu"
android:orderInCategory="100"
android:showAsAction="always"/>

</menu>


But I need to change it in code, not in the layout file. Is it possible?

Answer

Unfortunately, there is no easy way to change the SearchView icon to a custom drawable, since the theme attribute searchViewSearchIcon is not public. Check this answer for details.

Please use android:Theme.Holo.Light.DarkActionBar as the base for your theme. Then the default icons on the action bar should have a light color.

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