How to change SearchView textcolor? - android

My SearchView is located in a LinearLayout / RelativeLayout rather than the action bar.
Its default text color is white, how to change it?

Digging into the source code of the appcompat SearchView I found that it uses an AppCompatAutoCompleteTextView which by default uses the autoCompleteTextView style.
Creating a different autocomplete style and setting it in the app theme solved the problem for me.
<style name="SearchAutoCompleteTextView" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:textColor">#color/my_text_color</item>
<item name="android:textColorHint">#color/my_hint_color</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light">
...
<item name="autoCompleteTextViewStyle">#style/SearchAutoCompleteTextView</item>
</style>

For Androidx Library
SearchView searchView = (SearchView) findViewById(R.id.search);
EditText searchEditText = searchView.findViewById(androidx.appcompat.R.id.search_src_text);
searchEditText.setTextColor(getResources().getColor(R.color.white));
searchEditText.setHintTextColor(getResources().getColor(R.color.white));
For Android Support Library
SearchView searchView = (SearchView) findViewById(R.id.search);
EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchEditText.setTextColor(getResources().getColor(R.color.white));
searchEditText.setHintTextColor(getResources().getColor(R.color.white));

Try this,
SearchView searchView= (SearchView) findViewById(R.id.searchView1);
int id = searchView.getContext()
.getResources()
.getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);
or
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text))
.setHintTextColor(getResources().getColor(R.color.white));
or
searchView.setQueryHint(Html.fromHtml("<font color = #ffffff>" +
getResources().getString(R.string.your_str) + "</font>"));
This may helps you.

For me worked next approach:
1.add style into your styles.xml
<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
<item name="android:textColor">#color/white</item>
<item name="android:editTextColor">#color/white</item>
<item name="android:textColorHint">#color/light_gray</item>
</style>
2.add this line in your SearchView layout code
app:theme="#style/SearchViewStyle"

I would do this kind of job through the xml layout file. This can be found in the res/layout folder.
You would need to do something similar to the following:
Add this to the parent theme.
<item name="android:editTextColor">#android:color/white</item>
This should change the entered text.
You can also use something like this:
<item name="android:textColorHint">#android:color/white</item>
It will change the hint text for the SearchView.
Hope this helps :)

Just override the default color using the android:theme attribute:
<androidx.appcompat.widget.SearchView
android:theme="#style/ThemeOverlay.SearchView"
with
<style name="ThemeOverlay.SearchView" parent="">
<!-- Text color -->
<item name="android:editTextColor">#color/...</item>
<!-- Hint text color -->
<item name="android:textColorHint">#color/...</item>
</style>

Try this, if its not working try to change your theme.
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(getResources().getColor(R.color.white));
or try like this
searchView.setQueryHint(Html.fromHtml("<font color = #ffffff>" + getResources().getString(R.string.hintSearchMess) + "</font>"));

In this link colors of search icon, search hint icon, close icon, plate, query hint color, query color are changed

This worked for me:
EditText searchEditText = searchView.findViewById(androidx.appcompat.R.id.search_src_text);
searchEditText.setTextColor(getResources().getColor(R.color.white));
searchEditText.setHint("Search");
searchEditText.setHintTextColor(getResources().getColor(R.color.white));

Related

Android SearchView Text color

I am trying to make the text the user types of the search view white. "android:searchViewTextField" give an error. I can't find the right name for a global style:
<style name="AppTheme" parent="#style/_AppTheme"/>
<style name="_AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:searchViewTextField">#color/white_color</item>
</style>
Is there a global style which will only affect the text of the Searchview and not all text boxes?
Define the theme "SearchTextViewTheme"
<style name="SearchTextViewTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">#color/white_color</item>
</style>
Then inside the TextView
<TextView
style="#style/SearchTextViewTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
In fact applying theme must be explicitly defined in the layout XML. Therefore you do not have to worry about the theme affecting other text boxes
If your targed SDK is 20 or less, the attributes Goolge uses to style the SearchView are hidden and you’ll end up with compilation errors if you try overriding them in your theme.
You can use the AppCompat v20 SearchView instead of the the native SearchView following this tutorial. AppCompat exposes attributes like searchViewTextField and searchViewAutoCompleteTextView to change the style of the AutoCompleteTextView.
Here's how it's done ins Xamarin (I based the idea from Patrick's answer):
[assembly: ExportRenderer(typeof (CustomSearchBar), typeof (CustomSearchBarRenderer))]
namespace Bahai.Android.Renderers
{
public class CustomSearchBarRenderer : SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
SearchBar element = (SearchBar) this.Element;
var native = (global::Android.Widget.SearchView) Control;
// do whatever you want to the controls here!
//--------------------------------------------
// element.BackgroundColor = Color.Transparent;
// native.SetBackgroundColor(element.BackgroundColor.ToAndroid());
// native.SetBackgroundColor(Color.White.ToAndroid());
//The text color of the SearchBar / SearchView
AutoCompleteTextView textField = (AutoCompleteTextView)
(((Control.GetChildAt(0) as ViewGroup)
.GetChildAt(2) as ViewGroup)
.GetChildAt(1) as ViewGroup)
.GetChildAt(0);
if (textField != null)
textField.SetTextColor(Color.White.ToAndroid());
}
}
}
}
this did the trick
<style name="myTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:editTextColor">#fffff</item>
</style>
The above solutions might work in java but they don't work in xamarin and i guess this solution will work in java.

Set text color to title of sherlokactionbar for android devices having 2.3

I am using actionbarsherlok library for my android project to support actionbar for below 3.0 devices.I managed to change text color to black/Blue for actionbar title for particular screens on above android 3.0 .
For this to achieve ,I found this which is working on above android 3.0
int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView titleTv= (TextView) findViewById(titleId);
if(titleTv!= null){
titleTv.setTextColor(getResources().getColor(R.color.blue));
titleTv.setTypeface(Typeface.createFromAsset(getAssets(),
"helvetica_medium.otf"));
}
But, for devices having android 2.3 ,I am getting titleTv= null.
Is there any solution for this ?
Thanks in advance.
After lot of searching finally got the answer
I just added this to style.xml
<style name="Actionbar.Music.TitleText" parent="#style/Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyApp.SherlockActionBarStyle</item>
<item name="android:actionBarStyle">#style/MyApp.SherlockActionBarStyle</item>
</style>
<style name="MyApp.SherlockActionBarStyle" parent="#style/Widget.Sherlock.ActionBar">
<item name="titleTextStyle">#style/MyApp.ActionBar.TextAppearance</item>
</style>
<style name="MyApp.ActionBar.TextAppearance" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textColor">#color/blue</item>
</style>
and used that theme for activity for which I wanted title to be blue/black
android:theme="#style/Actionbar.Music.TitleText"
Also with below code in oncreate of that activity whose actionbar title color I wanted to be blue/black
int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView titleTv= (TextView) findViewById(titleId);
if(titleTv!= null){
titleTv.setTextColor(getResources().getColor(R.color.blue));
titleTv.setTypeface(Typeface.createFromAsset(getAssets(),
"helvetica_medium.otf"));
}

How to change the autocomplete text color for search view inside of ActionBarSherlock with dark background?

I have my own theme for ActionBarSherlock based on Theme.Sherlock.Light.DarkActionBar, here are my styles:
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/action_bar</item>
<item name="background">#drawable/action_bar</item>
</style>
Where #drawable/action_bar is an xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#color/color_action_bar_bottom_line" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#color/color_action_bar_background" />
</shape>
</item>
</layer-list>
Everything looks great except one thing: the text in the SearchView (when I use the search mode in ActionBar) is "dark on dark", so I cannot see anything. I tried to set the text colors for SearchView manually:
AutoCompleteTextView searchTextView =
(AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchTextView.setTextColor(Color.WHITE);
searchTextView.setHintTextColor(Color.LTGRAY);
searchTextView.setHighlightColor(Color.WHITE);
searchTextView.setLinkTextColor(Color.WHITE);
This helped a lot but I cannot change the color of autocomplete text:
As you see, it's still black. How can I set the white text color for this kind of text?
Try this code
SearchView searchView = new SearchView(context);
LinearLayout linearLayout1 = (LinearLayout) searchView.getChildAt(0);
LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
autoComplete.setTextColor(Color.WHITE);
or
SearchView searchView = new SearchView(context);
AutoCompleteTextView search_text = (AutoCompleteTextView) searchView.findViewById(searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null));
search_text.setTextColor(Color.WHITE);
It's from my own answer here How to set SearchView TextSize?
I solved this by disabling autocomplete feature (it will be disabled if you'll set the edit type to Visible Password), but this solution is not very good and I'm still in search for better one.
private SearchView getSearchView() {
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setQueryHint("Search for items");
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
AutoCompleteTextView searchTextView =
(AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
if (searchTextView != null) {
searchTextView.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
searchTextView.setTypeface(Typeface.DEFAULT);
}
return searchView;
}
I think your are using a Light Theme with a custom dark action bar theme. You could try to change the theme of the AutoCompleteTextView to a dark one. Try to add this in your theme :
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="searchAutoCompleteTextView">#style/Widget.Sherlock.SearchAutoCompleteTextView</item>
<item name="android:searchAutoCompleteTextView">#style/Widget.Sherlock.SearchAutoCompleteTextView</item>
<item name="searchAutoCompleteTextViewStyle">#style/Widget.Sherlock.SearchAutoCompleteTextView</item>
<item name="android:searchAutoCompleteTextViewStyle">#style/Widget.Sherlock.SearchAutoCompleteTextView</item>
<item name="textAppearanceLargePopupMenu">#style/Widget.Sherlock.SearchAutoCompleteTextView</item>
<item name="android:textAppearanceLargePopupMenu">#style/Widget.Sherlock.SearchAutoCompleteTextView</item>
<item name="textAppearanceSmallPopupMenu">#style/Widget.Sherlock.SearchAutoCompleteTextView</item>
<item name="android:textAppearanceSmallPopupMenu">#style/Widget.Sherlock.SearchAutoCompleteTextView</item>
</style>
Edit : not sure about the added lines but you can try. I spot it in some fixes for the HoloEverywhere library.
May be there are is best way to do this , but used the very simple way, I used library for that
#Override
public boolean onCreateOptionsMenu(Menu menu) {
searchMenuItem = CollapsibleMenuUtils.addSearchMenuItem(menu, false,
textWatcher);
return true;
}
set the boolean value for true/false for setting Light/Dark theme
addSearchMenuItem(Menu menu, boolean isLightTheme, TextWatcher
textWatcher)
Adding collapsible search menu item to the menu.
Parameters: menu isLightTheme - true if use light them for ActionBar,
else false textWatcher
for changing the text color i changed the librery's layout/ holodark.xml
<AutoCompleteTextView
android:id="#+id/search_src_text"
android:layout_width="0dp"
.
.
android:textColor="#android:color/white" />
Here iam useing SearchView like this it's working nice searchtext color also in white color.
this one res/menu and name is applications_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/Accounts"
android:icon="#drawable/ic_launcher">
</item>
<item
android:id="#+id/menu_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/ic_launcher"
android:showAsAction="ifRoom"
android:title="menu_search">
</item>
</menu>
this one use in activity when you search like this
new MenuInflater(this).inflate(R.menu.applications_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
here is screen
The issue is that the SearchView is initialized without properly considering the ActionBar style (in this case Dark ActionBar on Light) that is set. And the answer is to use the ActionBar themed Context; retrieved by Activity.getActionBar().getThemedContext(). This is mentioned at the bottom of ABS Migration:
If you are using list navigation pay special attention to the 'List Navigation' example in the demos sample for direction on proper use. You need to use the library-provided layouts for both the item view and dropdown view as well as use the themed context from the action bar.
My code is how it is done in standard Android, you'd have to get the ActionBar however appropriate. If you pass the themed Context to the SearchView then it will use the appropriate style, namely, it won't render itself as if it were on a light background.

Android SearchView Icon

I want to disable the Mag icon displayed inside the search view component. Any idea how to reference it and remove it or replace it with another drawable ?
Since the wording of the question does not contain any mention of ActionBarSherlock (except for the tag) and comments have been added that the accepted answer does not work for standard and/or support library action bar, I'm posting another answer. Here is the Java code for onCreate:
// obtain action bar
ActionBar actionBar = getSupportActionBar();
// find SearchView (im my case it's in a custom layout because of left alignment)
View v = actionBar.getCustomView();
SearchView searchView = (SearchView)v.findViewById(R.id.search_view);
ImageView icon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
// method 1: does not work persistently, because the next line
// should be probably called after every manipulation with SearchView
// icon.setVisibility(View.GONE);
// method 2: working code
icon.setAdjustViewBounds(true);
icon.setMaxWidth(0);
icon.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
icon.setImageDrawable(null);
According to this post, while using a SearchView from the support library (android-support-v7-appcompat in my case) with setIconifiedByDefault(false) the icon is displayed outside edit textbox (SearchAutoComplete). Otherwise (setIconifiedByDefault(true)) it's displayed inside the box. The presented code is used for disabled "iconification" by default, and may require some changes to work with "iconified" search view. I don't know if the same applies to ActionBarSherlock.
Hope this helps.
This icon is hint. So you can simply set new hint text.
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
searchPlate.setHint("Search");
If you want icon as hint text use spanable string with ImageSpan
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
searchPlate.setTextColor(getResources().getColor(R.color.search_text_color));
SpannableString string = new SpannableString(" ");
Drawable d = getResources().getDrawable(R.drawable.ic_search);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
string.setSpan(span, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
searchPlate.setHint(string);
In your theme:
<style name="Theme" parent="Your parent theme">
<item name="android:searchViewSearchIcon">#android:drawable/ic_search</item>
</style>
Edit:
searchViewSearchIcon is a private attribute. This answer therefore does not work (on the native ActionBar).
You have to add this line in your MenuItem android:iconifiedByDefault="#android:color/transparent"
<item
android:id="#+id/activity_home_action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/activity_home_search_title"
android:iconifiedByDefault="#android:color/transparent"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView" />
Or you can make programatically searchView.setIconifiedByDefault(true);
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
getMenuInflater().inflate(R.menu.home, menu);
MenuItem searchMenuItem = menu.findItem(R.id.activity_home_action_search);
SearchView searchView = (SearchView) searchMenuItem.getActionView();
searchView.setIconifiedByDefault(true);
}
To remove the hint search button:
mNearMeSearchBar = (SearchView) mView.findViewById(R.id.nearme_search_component_nearme_edittext);
mNearMeSearchBar.setIconifiedByDefault(false); //Removes Search Hint Icon
To change the search button drawable:
int searchImgId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
ImageView v = (ImageView) mNearMeSearchBar.findViewById(searchImgId);
v.setImageResource(R.drawable.ic_compass);
You have to customize the SearchView style like this:
<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView">
<!-- Search button icon -->
<item name="searchIcon">#drawable/ic_arrow_back</item>
</style>
And then add it in your AppTheme.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- your other colors and styles -->
<item name="searchViewStyle">#style/MySearchViewStyle</item>
</style>
And apply it to your search view using the tag style:
<android.support.v7.widget.SearchView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/searchView"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:queryHint="#string/search_hint"
android:focusable="true"
android:focusableInTouchMode="true"
style="#style/MySearchViewStyle"
app:iconifiedByDefault="false" />
Hope it helps!
If you are using the v7 app compat library you can easily change this in the theme. In your theme that extends from an AppCompat theme just add a line like:
<item name="searchViewSearchIcon">#drawable/ic_search</item>
These lines removed the magnifying glass:
//remove search icon
mSearchView.setIconifiedByDefault(false);
ImageView icon = (ImageView) mSearchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
icon.setVisibility(View.GONE);
In your theme style include this:
<style name="YourTheme.Toolbar">
<item name="searchViewStyle">#style/YourActionBarSearch</item>
<item name="editTextColor">#color/your_ab_text_color</item>
<item name="android:textColorHint">#color/your_ab_hint_color</item>
</style>
You can now define the style of the SearchView with searchViewStyle, and editTextColor will set the color of the text in the search box. By setting android:textColorHint you will also set the color of the hint, e.g. "Search...".
<style name="YourActionBarSearch" parent="#style/Widget.Holo.SearchView">
<item name="searchIcon">#drawable/ic_ab_search</item>
<item name="queryBackground">#null</item>
<item name="submitBackground">#null</item>
<item name="searchHintIcon">#null</item>
<item name="defaultQueryHint">#null</item>
<item name="closeIcon">#drawable/ic_ab_small_search_close</item>
</style>
This will style your search view as you like, more or less. The field searchIcon is the icon in the action bar. The field searchHintIcon is the small icon to the left of the hint in the search field, which you are asking for in your question; set it to #null to remove the icon. The field closeIcon is the close icon at the right side of the search field.
In xml in searchView component add next :
app:searchHintIcon="#null"

Customizing android.widget.SearchView

Is it possible to customize layout of android.widget.SearchView (I'm using it in actionBar)?
I want to change icon and TextField background.
I've found the only one way to do that- to use reflections.
SearchView mSearchView = (SearchView)menu.findItem(R.id.search).getActionView();
try
{
Field searchField = SearchView.class.getDeclaredField("mSearchButton");
searchField.setAccessible(true);
ImageView searchBtn = (ImageView)searchField.get(mSearchView);
searchBtn.setImageResource(R.drawable.search_img);
searchField = SearchView.class.getDeclaredField("mSearchPlate");
searchField.setAccessible(true);
LinearLayout searchPlate = (LinearLayout)searchField.get(mSearchView);
((ImageView)searchPlate.getChildAt(0)).setImageResource(R.drawable.search_img);
searchPlate.setBackgroundResource(R.drawable.edit_text_bkg);
}
catch (NoSuchFieldException e)
{
Log.e(TAG,e.getMessage(),e);
}
catch (IllegalAccessException e)
{
Log.e(TAG,e.getMessage(),e);
}
If you use Appcompat v7, there is a way to do it without using reflection:
Declare the following style, and customize only those properties you need to customize, remove the rest (so they are inerhited from the parent style):
<style name="Widget.AppCompat.SearchView.CustomSearchView" parent="#style/Widget.AppCompat.SearchView">
<item name="layout">#layout/abc_search_view</item>
<item name="queryBackground">#drawable/abc_textfield_search_material</item>
<item name="submitBackground">#drawable/abc_textfield_search_material</item>
<item name="closeIcon">#drawable/abc_ic_clear_mtrl_alpha</item>
<item name="goIcon">#drawable/abc_ic_go_search_api_mtrl_alpha</item>
<item name="voiceIcon">#drawable/abc_ic_voice_search_api_mtrl_alpha</item>
<item name="commitIcon">#drawable/abc_ic_commit_search_api_mtrl_alpha</item>
<item name="suggestionRowLayout">#layout/abc_search_dropdown_item_icons_2line</item>
<item name="searchIcon">#drawable/ic_action_search</item>
</style>
Now, in your theme, use the same property:
<item name="searchViewStyle">#style/Widget.AppCompat.SearchView.Bonial</item>
Of course, your theme must inherit from one of the AppCompat themes, in my case, it was something like this:
<style name="Theme.MyActionBarActivity" parent="#style/Theme.AppCompat.Light">
Also your activities should extend ActionBarActivity and use the "support" version of the action bar methods. More info here.
I also read an article of a guy that declared the styles in some other way, but also using AppCompat v7:
http://www.jayway.com/2014/06/02/android-theming-the-actionbar/
If you are using android native SearchView and you want to change small search icon, which appears when searchView is expanded, then you are in trouble. Because attribute searchViewSearchIcon is internal, and can't be modified using styles.
Code snippet from SearchView class:
private int getSearchIconId() {
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(com.android.internal.R.attr.searchViewSearchIcon,
outValue, true);
return outValue.resourceId;
}
In ActionBarSherlock:
<style name="Your_Theme" parent="#style/Theme.Sherlock">
<item name="searchViewSearchIcon"> #drawable/ic_menu_search </item>
</style>
In Holo:
<style name="Your_Theme" parent="#style/Theme.Light">
<item name="android:searchViewSearchIcon"> #drawable/ic_search </item>
</style>

Categories

Resources