Action Bar Search View

This example shows how you can create search view onto the action bar.


1.) Create a new project by File-> New -> Android Project name it ActionBarSearchView.

2.) Create and write following into menusearchview_in_menu.xml:




3.) Write following into main.xml:




4.) Run for output.


1.) Create a project named ActionBarSearchView and set the information as stated in the image.

Build Target: Android 4.0
Application Name: ActionBarSearchView
Package Name: com. example. ActionBarSearchView
Activity Name: ActionBarSearchView
Min SDK Version: 14

2.) Open file and write following code there:




3.) Compile and build the project.

Leave a Comment:

panakj says May 18, 2012

plese help the google map my project show

Search with SearchView | says October 17, 2012

[…] used this example to implement search in my app. This means, when I execute a search, the application searches for […]

Peter says December 8, 2012

Thank you! Very useful post!

Ashim says February 1, 2013

Awesome one!

Pedro says March 4, 2013

Is this line of code needed in order to show the action bar?


paypal hack april 2013 says June 4, 2013

Having read this I thought it was really informative. I appreciate you spending some time and energy to put this article together. I once again find myself spending a significant amount of time both reading and posting comments. But so what, it was still worthwhile!

Prashant says July 17, 2013

Hii how can i use the same in gingerbread version……………
i want to use search view in android 2.3 mobiles

Nandy says September 10, 2013

Thanks for the tutorial. Very helpful.

I would like to add an image instead of a label to indicate the name of the app.. I could do it by adding custom title bar. Unfortunately, adding a custom title bar disables using menu items and related features provided by the action bar.

Is there a way to use a custom action bar like what you have shown here along with a custom title bar tod an image for the title of the app?

Thanks.. Any help is appreciated..

Umair says November 6, 2013

Thanks a lot, it really helped.

Bhargav says December 22, 2014

i want to provide custom suggestion in search view widget how can i do ?
in custom suggestion i want to provide city name

Hemendra Gangwar says December 28, 2014

Hey thank you very much..This code is working correctly..its very helpful…

vikas chauhan says April 17, 2015

good search bar is showing only before the xml editing,then it disappear after the code is written in java file .so not working for me

Add Your Reply