1. Create the Menu.xml configuration file under the res/menu/folder
<menu
Xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:id= "@+id/search" android:title= "@string/search"
android:icon= "@drawable/search_app_icon"
android:showasaction= "Ifroom|withtext"//in Actionbar display,
android:actionviewclass= "Android.widget.SearchView"
></item>
</menu>
2. Create a new activity and add a menu item to the activity, Createoptionsmenu code
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
TODO auto-generated Method Stub
Mi.inflate (R.menu.my_menu, menu);
MenuItem Search=menu.finditem (R.id.search);
Search.collapseactionview ();
Searchview searchview= (Searchview) Search.getactionview ();
Searchview.seticonifiedbydefault (FALSE);
Searchmanager msearchmanager= (Searchmanager) Getsystemservice (Context.search_service);
Searchableinfo Info=msearchmanager.getsearchableinfo (Getcomponentname ());
Searchview.setsearchableinfo (info); Need to build searchable.xml in XML file, search box config file
return true;
}
3. Under the XML folder resume Searchable.xml
<searchable xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:label= "@string/app_name"
android:hint= "@string/search_title"
android:searchsettingsdescription= "@string/search_title"
Android:searchsuggestauthority= "Com.digua.fncontact.familyName"
android:searchsuggestintentaction= "Android.intent.action.VIEW"
Android:searchsuggestintentdata= "Content://com.digua.fncontact.familyname/fname"
Android:searchsuggestselection= "?"
android:searchsuggestthreshold= "1"
Android:inputtype= "Text"
Android:voicesearchmode= "Showvoicesearchbutton|launchrecognizer"
Android:searchmode= "Queryrewritefromtext"
Android:includeinglobalsearch= "true"
Android:queryafterzeroresults= "true"
>
</searchable>
Original address: http://blog.csdn.net/suichukexun/article/details/7592113
Android Searchview Basic Use