Setting hint text for search widget when used as part of menu

Related searches

I have a menu item as part of my action bar menu, and I am setting the action view class to the search widget like so:

   <item android:id="@+id/menu_search"
        android:actionViewClass="android.widget.SearchView" />

This makes the search widget pop out when it is clicked - however, I want it to always be visible, and I also want to be able to set the query hint etc.

When I attempt to call SearchView searchItem = (SearchView) menu.findItem( to get a reference to it, it throws an error as the item cannot be cast to a SearchView.

This will make the ActionView search box always show, by default:


This tells the search box to always be expanded. Iconified means that you need to tap the icon to make the search box appear.

Setting hint text for search widget when used as part of menu, I have a menu item as part of my action bar menu, and I am setting the action view class to the search widget like so: <item android:id="@+id/menu_search"� Add the Search widget to your homepage. Learn how to add a widget. On your Android phone or tablet, open the Google app . At the bottom right, tap More Customize widget. At the bottom, tap the icons to customize the color, shape, transparency and Google logo. When you’re finished, tap Done.

You can set hint text to searchview using the api setQueryHint (CharSequence hint)

SearchView searchView = (SearchView) menu.findItem(;
searchView.setQueryHint("Query Hint");

Refer the documentation

android.widget.SearchView.setQueryHint java code examples , SearchView searchView = (SearchView) menu. Best Java code snippets using android.widget. menu); // Get the SearchView and set the searchable configuration SearchManager setQueryHint("some text"); smenu=menu.add(" smenu"). Below is an example code which get the hint text that will be displayed in the query text field of a search view. SearchView simpleSearchView = (SearchView) findViewById(; // inititate a search view CharSequence queryHint = simpleSearchView.getQueryHint(); // get the hint text that will be displayed in the query text field

Try getActionView; findItem is returning a MenuItem, not the View it uses


Creating a Search Interface, By default, the search widget behaves like a standard EditText widget and It includes settings for features such as voice search, search suggestion, and hint text for the using the search widget instead (see Using the Search Widget section). For instance, you should add a Search button in your Options Menu or UI� In the Web Part, click the Search Box Web Part Menu arrow, and then click Edit Web Part. In the Search Box tool pane, under Properties for Search Box, expand Which search results page should queries be sent to. To use the settings that are defined on the Search Settings page, select the Use this site's Search Settings check box.

minimum API level should be 11 then The error will not be shown

    android:targetSdkVersion="18" />

SearchView, When the SearchView is used in an ActionBar as an action view for a collapsible menu item, it needs to be set to iconified by default using� Beginning in Android 3.0, using the SearchView widget as an item in the app bar is the preferred way to provide search in your app. Like with all items in the app bar, you can define the SearchView to show at all times, only when there is room, or as a collapsible action, which displays the SearchView as an icon initially, then takes up the entire app bar as a search field when the user clicks

I added these lines of code and it worked.


Sample code

public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.findItem(;
    MaterialSearchView searchView = findViewById(;
    return true;

Material Search View library github link

Create and style a text field, TextField is the most commonly used text input widget. TextField( decoration: InputDecoration( border: InputBorder.none, hintText: 'Enter a search term' ), );. To do so, they click the drop-down arrow in the search box and choose a layer from the drop-down menu. The hint text you provided will be displayed in the search box. Once their keywords are typed in the search box, the map will zoom to the located feature and a pop-up with any available attribute information will be displayed.

On the search page, the AppBar is white with black text This won’t work if you need your search page theme to match the rest of your application. And there isn’t an abstract method to override

Text – used to enter HTML, JavaScript, or just plain text. Multiple instances of this widget can be added to the Current Widgets list. Using Text Widgets details a number of possible uses for text widgets. Title area — a description of the text widget; Text area — use this area to enter text, valid HTML, or even valid JavaScript.

If the derived widget wishes to use escape for its own purposes, it can call super after it has processed the character (if it does not wish to consume the escape). See keyboard_on_key_down() keyboard_suggestions¶ If True provides auto suggestions on top of keyboard. This will only work if input_type is set to text.

  • thanks, that's worked! do you know how to get the action view to be always displayed rather than only when the menu item is pressed?
  • Sorry, I'm not sure what you mean. Can you explain what's happening right now?