开发者

Showing a search bar in Android

I'm having trouble when trying to show the search bar at the top of my app. I just want this bar to be visible for the hole application (in all the activities) even when the app starts, with no need for the user to press a button, I'm trying to use android's searchable function. Here's what I've got so far:

manifest.xml

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Main"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>开发者_开发知识库;

    <activity android:name=".BigImageView">
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
               android:resource="@xml/searchable"/>
    </activity>
    <!-- declare the default searchable Activity for the whole app -->
    <meta-data android:name="android.app.default_searchable"
           android:value=".BigImageView" />

</application>

res/xml/searchable.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint" >

Can I accomplish this or does the user need to press a buttons to invoke the search bar?


You could put

onSearchRequested();

in onResume() - but the search bar would hide if another component will get the focus.

If that's not what you want, you should implement your own search bar (i.e. with AutoCompleteTextView).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜