在 actionbar中使用 searchview

package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <meta-data
            android:name="android.app.default_searchable"
            android:value=".SearchActivity" />
    </activity>
    <activity
        android:name=".SearchActivity"
        android:label="@string/app_name" >

        <!-- This intent-filter identifies this activity as "searchable" -->

        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <!-- This metadata entry provides further configuration details for searches -->
        <!-- that are handled by this activity. -->

        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>
</application>

 注意 "android.app.searchable" metadata必须在 "results" activity, main activity (或者搜索 activity 包含SearchView) 需要制定 "android.app.default_searchable".

猜你喜欢

转载自wang-peng1.iteye.com/blog/1850185