Styling a SearchView in Android Action Bar

TheLettuceMaster picture TheLettuceMaster · Jul 17, 2012 · Viewed 55.1k times · Source

I have a search widget in my Action Bar like this:

Search Widget in Action Bar

(1) How do I change the color of the text that says "iPhone"?

(2) Also, if you notice the gray X -- the entire Search Widget is that color as well when it is in an icon position. I am on Holo.Theme.Light and utilizing my own mods to it.

How do I change these two styles for the widget in my styles.xml file (assuming that is where you make the changes for a search widget)?

Answer

Adidas picture Adidas · Feb 4, 2014

I have been spending many time for this but finally: :-)

  1. To change the text color :
((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setTextColor(Color.WHITE);

or this one for AndroidX:

((EditText)searchView.findViewById(androidx.appcompat.R.id.search_src_text)).setTextColor(Color.WHITE);
  1. To change the text hint:
((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(Color.WHITE);

or this one for AndroidX:

((EditText)searchView.findViewById(androidx.appcompat.R.id.search_src_text)).setHintTextColor(Color.WHITE);