Android : How to apply style for SearchViewCompat suggestions?

on Wednesday, September 3, 2014


I use SherlockActionBar, and use SearchViewCompat for searching from action bar. This is the code:



@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem item = menu.add(getResources().getString(R.string.search));
item.setIcon(android.R.drawable.ic_menu_search);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

SherlockFragmentActivity parentActivity = getSherlockActivity();
mSearchView = (SearchView) SearchViewCompat.newSearchView(parentActivity.getSupportActionBar().getThemedContext());
if (mSearchView != null) {
mSearchView.setQueryHint(getResources().getString(R.string.hotel_by_name));
mSearchManager = (SearchManager) parentActivity.getSystemService(Context.SEARCH_SERVICE);

mSearchView.setSearchableInfo(mSearchManager.getSearchableInfo(parentActivity.getComponentName()));
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
loadHotelsSearchData(newText);
return false;
}
});

mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
@Override
public boolean onSuggestionSelect(int position) {
return false;
}

@Override
public boolean onSuggestionClick(int position) {
...
}
item.setActionView(mSearchView);
}
}


So I found, how to set hint text color: @style/actionBarWidgetTheme



<style name="actionBarWidgetTheme" parent="@android:style/Theme.Holo">
<item name="android:textColorHint">@color/actionBarSearchViewText</item>
</style>


But I can't find how to set background and text color for suggestions. Any method from internet did not worked. My suggestions look like this:


http://i.imgur.com/0ZLJN4g.png


I try to make background blue with the white text. How can I do it?


0 comments:

Post a Comment