Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Searchview with background hint

Tags:

I am a newbie to android development, and would like to know if it is possible to create an search view with background hint, which changes automatically, as the user types in the search view box. for example, like in the Google search, where the grey part in the background gives the user the options of filling in.

like image 627
vignesh s Avatar asked Oct 24 '11 20:10

vignesh s


People also ask

How to display hint in SearchView android?

If the hint's desired to be visible in the Non-Active State of SearchView set android:iconifiedByDefault to "false" . If it's undesired set android:iconifiedByDefault to "true" . This is the answer without creating a function or code in the Activity. Just add this in the layout.

What is android SearchView?

android.widget.SearchView. A widget that provides a user interface for the user to enter a search query and submit a request to a search provider. Shows a list of query suggestions or results, if available, and allows the user to pick a suggestion or result to launch into.


2 Answers

You can add SearchView hint by following below :

search.setQueryHint("Google Search");

You can set Background color of SearchView by following below :

search.setBackgroundColor(Color.RED);
like image 77
Balaji Avatar answered Sep 27 '22 18:09

Balaji


Try something like this :

SearchView searchView = new SearchView(canvas.getContext());
searchView.setQueryHint("Type your text here");
searchView.setBackgroundColor(Color.WHITE);

OptionCommand searchCommand = new OptionCommand();
searchCommand.setActionView(searchView);
searchCommand.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
like image 29
lokoko Avatar answered Sep 27 '22 19:09

lokoko