Android 调用系统搜素框

AndroidManifest.xml 中的Activity文件配置

<activity
    android:name=".map.baidu.BaiduMapActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/app_name"
    android:windowSoftInputMode="adjustUnspecified|stateHidden" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.SEARCH" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    <meta-data
        android:name="android.app.searchable"
        android:resource="@xml/searchable" />
</activity>

res/xml/earchable.xml 文件配置 
<?xml version="1.0" encoding="utf-8"?> 
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:hint="@string/app_name"
    android:label="@string/app_name"
    android:searchButtonText="@string/app_name"
    android:searchSettingsDescription="@string/app_name" >
</searchable>
label一定要用@string的方式,否则不会显示搜素框

 

Activity中的调用

Intent queryIntent = getIntent();
final String queryAction = queryIntent.getAction();
/* 取得当按下搜索时的Intent */
if (Intent.ACTION_SEARCH.equals(queryAction))
{
  /* 取得欲搜索的字符串 */
  String query = queryIntent.getStringExtra(SearchManager.QUERY);
  Log.d(TAG,query);
}
/* 按下键盘即弹出搜索框 */
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);

 

posted @ 2012-04-19 11:24  骨头  阅读(804)  评论(0编辑  收藏  举报