Android Searchview Basic Use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.