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));

also see this

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

Share:
81,458
Juhani
Author by

Juhani

Updated on July 09, 2022

Comments

  • Juhani
    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?

    Action bar search view hint text

  • Roger Alien
    Roger Alien over 10 years
    android:actionBarWidgetTheme is available only at API lvl 14.
  • Steve Westbrook
    Steve Westbrook over 10 years
    Could you add a little explanation?
  • Vadim Teselkin
    Vadim Teselkin over 10 years
    What's not to understand? Change the color of text and hint text via html tags ...
  • Maksim Dmitriev
    Maksim Dmitriev over 10 years
    The solution doesn't work. stackoverflow.com/a/14364222 does, but it's really a workaround.
  • giltsl
    giltsl almost 10 years
    Nice to know, how to find search_src_text. Thanks.
  • Glenn.nz
    Glenn.nz almost 10 years
    Ill 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
    aleb over 9 years
    "android:actionBarWidgetTheme requires API level 14"
  • user2331095
    user2331095 about 9 years
    I found that android.support.v7.appcompat is not necessary, just use searchView.findViewById(R.id.search_src_text) is ok.
  • Chirag Khatsuriya
    Chirag Khatsuriya almost 9 years
    can we change font size using html.fromhtml?
  • Noumenon
    Noumenon almost 8 years
    This is pretty close to a duplicate of stackoverflow.com/a/29026547/733092 above (but better formatted).
  • Radu
    Radu over 7 years
    Yes! With theming!
  • Mazharul Islam
    Mazharul Islam over 7 years
    Best Solution ever
  • Red M
    Red M over 7 years
    This does not work <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  • Graydyn Young
    Graydyn Young over 6 years
    This solution works for the actual search text, but does not affect the hint text color.
  • Amr Angry
    Amr Angry over 6 years
    it works with me in its time don't knew by now :) sorry for that @GraydynYoung
  • user1354603
    user1354603 almost 6 years
    This 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
    user924 over 5 years
    yes, 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
    Vadim Teselkin almost 5 years
    If you need only different size, you can use simple <small> or <big>
  • someone
    someone about 4 years
    Try 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...).