I want to change the text color of search view hint, but I tried in many ways with no success.
Like in this post: Changing action bar searchview hint text color
I'm using Appcompat, support library of actionbar.
I tried this with null pointer return:
AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(R.color.white));
searchText.setTextColor(getResources().getColor(R.color.white));
Wrong id for the AutoCompleteTextView, I guess. Unless you use a custom Action Bar Search widget. Try smth. like the following:
((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text))
.setHintTextColor(getResources().getColor(R.color.white));
I found the answer here too:
getMenuInflater().inflate(R.menu.menu_home, menu);
MenuItem searchItem = menu.findItem(R.id.item_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
mSearchView.setOnQueryTextListener(this);
mSearchView.setQueryHint(getString(R.string.text));
SearchAutoComplete searchAutoComplete = (SearchAutoComplete) mSearchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchAutoComplete.setHintTextColor(mRes.getColor(android.R.color.white));
searchAutoComplete.setTextSize(14);
Using the following code:
getResources().getColor(R.color.white)
it is possible that an alert saying that getColor(int) is deprecated
appears. This is because from api 23, a new getColor()
method was added to the ContextCompat.
So just use the following:
((EditText) searchView.findViewById (android.support.v7.appcompat.R.id.search_src_text))
.setHintTextColor (ContextCompat.getColor (getBaseContext(), Color.WHITE));
It worked for me.