标签:
1.在res/menu/文件夹下建立menu.xml 配置文件
<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" //在actionBar显示,
android:actionViewClass="android.widget.SearchView"
></item>
</menu>
2.新建一个activity,并为该activity添加菜单项,CreateOptionSMenu代码
@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); //需要在Xml文件加下建立searchable.xml,搜索框配置文件
return true;
}
3.在xml文件夹下简历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>
原文地址:http://blog.csdn.net/suichukexun/article/details/7592113
标签:
原文地址:http://www.cnblogs.com/blkspm/p/5200211.html