How to change the textcolor or queryhint textcolor of an Android SearchView in AndroidX?

Viewed 556

The Android searchview has default queryhint textcolor and text color . How we can change the text color of edittext in Android Searchview using AndroidX

2 Answers

The searchView below is the reference variable of Searchview you are using .

JAVA:

    EditText editText = searchView.findViewById(androidx.appcompat.R.id.search_src_text);
    editText.setTextColor(Color.WHITE);
    editText.setHintTextColor(Color.GRAY);

KOTLIN

val editText = searchView.findViewById(androidx.appcompat.R.id.search_src_text)
editText.setTextColor(Color.WHITE)

You can do it programmatically if you wish and which is a pretty good trick, well I am telling you how to do it in XML:

  1. Go to your color.xml file which is in values under resources.
  2. You will find 3 colors defined there, Add colors there let suppose blue and orange colors like this

    <color name="colorblue">#FF0A7FE4</color>
    <color name="colororange">#F76707</color>
    
  3. Now got to the XML where you have that search box EditText

  4. In that editText view add attributes :

     android:textColorHint="@color/colorblue"
     android:textColor="@color/colororange"
    

    there you will find the hint color will be now changed to blue and the text color will now be orange.

Related