Changing action bar searchview hint text color
81,458
Solution 1
android:actionBarWidgetTheme
of your main theme should point to a style that has a android:textColorHint
in it. That one will allow changing the hint text color of the search view.
Solution 2
searchView.setQueryHint(Html.fromHtml("<font color = #ffffff>" + getResources().getString(R.string.hintSearchMess) + "</font>"));
Solution 3
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);
Solution 4
this worked for me, hope it helps
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(getResources().getColor(R.color.white));
Solution 5
I resolved it adding this property to the main theme:
<style name="AppTheme" parent="AppBaseTheme">
.....
.....
<item name="android:actionBarWidgetTheme">@style/MyActionBarWidgetTheme</item>
</style>
And then add the property i want to change in this case the hint color.
<style name="MyActionBarWidgetTheme" parent="@android:style/Theme.Holo">
.....
.....
<item name="android:textColorHint">@color/blanco_60</item>
</style>
Hope it helps :D
Author by
Juhani
Updated on July 09, 2022Comments
-
Juhani almost 2 years
How can I change the action bar search view hint text colour?
This question explains how to get the EditText when using ABS: Android ActionBar Customize Search View
Is there a android.R.id I could use to get a reference to the EditText so I could change the hint colour? Or is there some other way to change the colour?
-
Roger Alien over 10 years
android:actionBarWidgetTheme
is available only at API lvl 14. -
Steve Westbrook over 10 yearsCould you add a little explanation?
-
Vadim Teselkin over 10 yearsWhat's not to understand? Change the color of text and hint text via html tags ...
-
Maksim Dmitriev over 10 yearsThe solution doesn't work. stackoverflow.com/a/14364222 does, but it's really a workaround.
-
giltsl almost 10 yearsNice to know, how to find search_src_text. Thanks.
-
Glenn.nz almost 10 yearsIll just add a comment here, the parent for
android:actionBarWidgetTheme
style is a theme also. You can use@android:style/Theme.Holo
for the lighter search icon, and@android:style/Theme.Holo.Light
for the darker search icon. From here -
aleb over 9 years"android:actionBarWidgetTheme requires API level 14"
-
user2331095 about 9 yearsI found that
android.support.v7.appcompat
is not necessary, just usesearchView.findViewById(R.id.search_src_text)
is ok. -
Chirag Khatsuriya almost 9 yearscan we change font size using html.fromhtml?
-
Noumenon almost 8 yearsThis is pretty close to a duplicate of stackoverflow.com/a/29026547/733092 above (but better formatted).
-
Radu over 7 yearsYes! With theming!
-
Mazharul Islam over 7 yearsBest Solution ever
-
Red M over 7 yearsThis does not work
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
-
Graydyn Young over 6 yearsThis solution works for the actual search text, but does not affect the hint text color.
-
Amr Angry over 6 yearsit works with me in its time don't knew by now :) sorry for that @GraydynYoung
-
user1354603 almost 6 yearsThis worked for me. Except I created a new theme "SearchViewStyle" which inherits from my main app theme and then added it to my SearchView component like this: "android:theme="@style/SearchViewStyle"
-
user924 over 5 yearsyes, starting from 5 Android such things should be using app compat themes/styles, and support libraries which includes all of this are available for older versions as well
-
Vadim Teselkin almost 5 yearsIf you need only different size, you can use simple <small> or <big>
-
someone about 4 yearsTry don't use uppercase letters when it's not necessary. Doing that sends your comment to review queue, what let people like me (and you in future) reviewing a post that don't have nothing wrong (only the uppercase...).