在 Android 中显示搜索栏
我在尝试在应用程序顶部显示搜索栏时遇到问题。我只是希望这个栏对于洞应用程序(在所有活动中)可见,即使应用程序启动时,也不需要用户按下按钮,我正在尝试使用 android 的可搜索功能。这是我到目前为止所得到的:
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" >
我可以完成此操作吗?或者用户是否需要按按钮来调用搜索栏?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以放入
onResume()
- 但如果另一个组件获得焦点,搜索栏将隐藏。如果这不是您想要的,您应该实现自己的搜索栏(即使用 AutoCompleteTextView)。
You could put
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).