Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the background color of searchview autocomplete dropdown

I have a searchview with a content provider for custom suggestions, which are displayed in a dropdown. However, the dropdown background is dark while the text is black so it's not very visible. My app theme is inheriting from Theme.AppCompat.Light so everything else in my app is black text on a light background.

enter image description here

I want to change the background of the dropdown so the text is readable but I haven't found any way of doing so. The closest I got was following the solution here: Style Android SearchView Drop down popup But when the dropdown appears, stuff looks messed up.

enter image description here

Is there any working solution for this?

like image 918
dyancat Avatar asked Dec 02 '14 01:12

dyancat


2 Answers

i think you should use

SearchView.SearchAutoComplete autoCompleteTextView = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);
if (autoCompleteTextView != null) {
    autoCompleteTextView.setDropDownBackgroundDrawable(getResources().getDrawable(R.drawable.abc_popup_background_mtrl_mult));
}

this can set the SearchAutoComplete dropdown background to Light

like image 57
MoMo Wang Avatar answered Sep 17 '22 11:09

MoMo Wang


Simple solution

int autoCompleteTextViewID = getResources().getIdentifier("search_src_text", "id", getPackageName());
mSearchAutoCompleteTextView = mSearchView.findViewById(autoCompleteTextViewID);
mSearchAutoCompleteTextView.setDropDownBackgroundResource(R.color.white);

enter image description here

like image 38
Zain Avatar answered Sep 20 '22 11:09

Zain