prakash.developer prakash.developer - 5 months ago 64
Android Question

Set text color and hint text color to the text in SearchView

I want to set the text color and hint text color to the text in a which is not in ActionBar and not in Menu option.I have tried few ways mentioned in stackoverflow. But none of them is working.

int searchSrcTextId =getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchEditText = (EditText) searchView.findViewById(searchSrcTextId);

I tried the above code,but it is giving Null pointer exception at the setTextColor line.Any kind of help will be appreciated.Thanks in advance.


I would do this kind of job through the xml layout file. This can be found in the res/layout folder.

You would need to do something similar to the following:

Add this to the parent theme.

<item name="android:editTextColor">@android:color/white</item>

This should change the entered text.

You can also use something like this:

<item name="android:textColorHint">@android:color/white</item>

It will change the hint text for the SearchView.

Hope this helps :)