Action Bar Search View

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

Algorithm:

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.

Steps:

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 ActionBarSearchView.java file and write following code there:

 

 

 

3.) Compile and build the project.

Leave a Comment:

12 comments
panakj says May 18, 2012

plese help the google map my project show

Reply
Search with SearchView | Jisku.com says October 17, 2012

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

Reply
Peter says December 8, 2012

Thank you! Very useful post!

Reply
Ashim says February 1, 2013

Awesome one!

Reply
Pedro says March 4, 2013

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

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

Reply
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!

Reply
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

Reply
Nandy says September 10, 2013

Hi,
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..

Reply
Umair says November 6, 2013

Thanks a lot, it really helped.

Reply
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

Reply
Hemendra Gangwar says December 28, 2014

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

Reply
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

Reply
Add Your Reply