-1

I have a AppCompat SearchView and I wanted to change the color of the text in the SearchView. So I followed this answer.

So I typed the answer in my themes.xml and in the layout preview, the text color was black. But when I tested it on the emulator, the text color was white. I am attaching two screenshots as well.

XML Layout Preview

Emulator

What is the problem?

Spyware
  • 37
  • 8

1 Answers1

1

Found a solution. Create a new theme with the parent Widget.AppCompat.SearchView and then you can customize it's font, text size, text color etc.

Code;

<style name="SearchViewTheme" parent="Widget.AppCompat.SearchView">
    <item name="android:textColorHint">@color/somecolor</item>
    <item name="editTextColor">@color/somecolor</item>
    <item name="fontFamily">@font/somefont</item>
</style>
Spyware
  • 37
  • 8
  • for full backward and forward compatibility duplicate color params - one with `android:` prefix and one without. so there should be e.g. `"android:textColorHint"` AND `"textColorHint"` pointing on same color. and you are good to go :) – snachmsm Aug 25 '21 at 07:51
  • Ok @snachmsm Good advice – Spyware Aug 25 '21 at 07:52