Loading...

Simple Android SearchView Example

Search View is one of the most useful UI widget/components in android. Android search view widget can be used in action bar/ appbar/ toolbar or in your layout. Both search widget and dialog are used to search text, video, etc. In this tutorial, you will learn to implement search view widget in android application.

There are two types of search; one search widget and another search dialog. Search widget is placed anywhere in your app layout and search dialog is a UI component that is controlled by the android system. Search dialog appears at the top of activity.

Related:
Implementing SearchView in Android ActionBar
Setting Android ActionBar Subtitle and Color
Android Auto Complete using AutoCompleteTextView and MultiAutoCompleteTextView

Android Example: How to Add Search Function to Android App


Create a new android studio project with the project name Simple Android SearchView. Open your XML layout file and add a search view widget with id. Following is the complete content of XML layout file.

res/layout/searchview_android_example.xml

Now open your java activity file and set searchView.setOnQueryTextListener and then override onQueryTextSubmit and onQueryTextChange method. Following is the complete code of java activity file.

src/SimpleAndroidSearchViewExample.java

Following is the content of styles.xml and AndroidManifest.xml file.

res/values/styles.xml

AndroidManifest.xml

Android Example: How to Add Search Function to Android App

Now, run your Simple Android SearchView Example application and click on the search icon which will look like above screenshot. If you type something in the search box the text will appear in toast in real time.
XML 8076419556308668733
Home item