Skip to content

Most visited

Recently visited


Remaining Backward Compatible

The SearchView and action bar are only available on Android 3.0 and later. To support older platforms, you can fall back to the search dialog. The search dialog is a system provided UI that overlays on top of your application when invoked.

Set Minimum and Target API levels

To setup the search dialog, first declare in your manifest that you want to support older devices, but want to target Android 3.0 or later versions. When you do this, your application automatically uses the action bar on Android 3.0 or later and uses the traditional menu system on older devices:

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />


Provide the Search Dialog for Older Devices

To invoke the search dialog on older devices, call onSearchRequested() whenever a user selects the search menu item from the options menu. Because Android 3.0 and higher devices show the SearchView in the action bar (as demonstrated in the first lesson), only versions older than 3.0 call onOptionsItemSelected() when the user selects the search menu item.

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
            return true;
            return false;

Check the Android Build Version at Runtime

At runtime, check the device version to make sure an unsupported use of SearchView does not occur on older devices. In our example code, this happens in the onCreateOptionsMenu() method:

public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(, menu);

        SearchManager searchManager =
                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView =
                (SearchView) menu.findItem(;
    return true;
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)