怎么使用android中的搜索功能
如何使用android中的搜索功能
这几天使用到了搜索,没仔细深入,步骤大概是这样的
1.Activity中调用onSearchRequested();
2.AndroidManifest.xml中添加
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
@xml/searchable是自定义的,内容如下
<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/searchLabel" android:hint="@string/searchHint" android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" > </searchable>
3.点击@xml/searchable中的按钮的时候,android会搜索AndroidManifest.xml中的
<meta-data android:name="android.app.default_searchable" android:value=".SerachActivity" />
4.SerachActivity是自定义的Activity,通过以下代码
Intent intent = getIntent(); String action = intent .getAction(); if (Intent.ACTION_SEARCH.equals(action )) { String queryString = intent.getStringExtra(SearchManager.QUERY);//queryString是查询的字符串 }流程是这样的,有错误请指出,谢谢
1 楼
gmxstar
2011-05-18
事例看不了效果啊