6

I need to change the style of my SearchView in my ActionBar. In particular I need to change the text hint color and the SearchView icons if possible. How can I accomplish this in XML (is it even possible in XML)?

If this isn't possible, how can I easily recreate similar behavior with a custom view? The close/expand behavior of the SearchView is particularly useful for me.

galaxy infinite
  • 143
  • 3
  • 9
  • Have you found a solution for this question? Plase don't forget to notify us here - or if not specify your question please. :-) – Tobias Reich Jan 07 '13 at 09:31
  • I managed to modify the hint color like this: http://stackoverflow.com/questions/17791388/changing-action-bar-searchview-hint-text-color – argenkiwi Jul 28 '13 at 23:46

4 Answers4

7

Have you tried something like this (With ActionBarSherlock):

AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(R.color.white));
searchText.setTextColor(getResources().getColor(R.color.white));

It works fine for me.

Munchies
  • 444
  • 6
  • 14
Tobias Reich
  • 4,952
  • 3
  • 47
  • 90
1

It looks like you may need to supply a custom layout for your search action. I haven't been able to find any documents that talk about modifying the default SearchView. But this does allow the close/expand behavior.

http://developer.android.com/guide/topics/ui/actionbar.html#ActionView

Related questions:

Community
  • 1
  • 1
pforhan
  • 807
  • 8
  • 12
0

You need to create a new theme and use it in manifest file.

<style name="Theme.Test" parent="@style/Theme.AppCompat.Light">
   <item name="searchViewAutoCompleteTextView">@style/Theme.Test.SearchField</item>
</style>

<!-- Search edit text -->
<style name="Theme.Test.SearchField" parent="@style/Widget.AppCompat.Light.AutoCompleteTextView">
    <item name="android:textColor">@color/white</item>
    <item name="android:textColorHint">@color/white</item>
</style>

It worked fine for me.

rafaelsoma
  • 96
  • 1
  • 6
0

The right answer is to overload the action bar widget style with your own custom style. For holo light with dark action bar, put this in your own styles file such as res/values/styles_mytheme.xml:

<style name="Theme.MyTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarWidgetTheme">@style/Theme.MyTheme.Widget</item>
    <!-- your other custom styles -->
</style>

<style name="Theme.MyTheme.Widget" parent="@android:style/Theme.Holo">
    <item name="android:textColorHint">@android:color/white</item>
    <!-- your other custom widget styles -->
</style>

Make sure your application is using theme custom theme as described in enter link description here

johnarleyburns
  • 1,532
  • 12
  • 13