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.
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.
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.
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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With