一个 AndroidManifest.xml 中包含两个 searchable.xml 活动
我有一个 Android 应用程序,其中有一些不同的活动用于浏览从 RSS 下载的文章和图像。
我希望能够提供连接
<activity android:name=".search.SearchResultsActivity"
android:label="@string/search_results_activity_title" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable_articles"/>
</activity>
在
中,
<meta-data android:name="android.app.default_searchable"
android:value=".search.SearchResultsActivity" />
我现在可以从任何活动启动“搜索”对话框,并且它会启动 SearchResultsActivity
代码>.
我现在希望能够在用户是 ImageListActivity
时使用 searchable_images.xml
搜索图像,并在其他地方使用默认值。
我有一个 SearchResultsImageActivity
,其中包含以下元数据元素,并在 ImageListActivity
中使用相同的元素。
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable_images"/>
在按下 ImageListActivity
中的搜索按钮时,我从 searchable_articles.xml
中获取默认搜索。
如果我将 default_searchable
更改为 SearchResultsImageActivity
,则始终启动图像搜索,而永远不会启动文章搜索。
如果我完全删除 default_searchable
元数据元素,并仅添加 searchable
元数据选定的活动,则不会启动任何搜索。
我相当确定这应该是可能的,但我不知道我做错了什么。
I have an Android app which has a few different activities for browsing articles and images downloaded from RSS.
I'd like to be able to offer to hook up the search button to the Search dialog, using the a searchable.xml
file. I've managed to do this with one search, using:
<activity android:name=".search.SearchResultsActivity"
android:label="@string/search_results_activity_title" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable_articles"/>
</activity>
and in the <application />
<meta-data android:name="android.app.default_searchable"
android:value=".search.SearchResultsActivity" />
I can now launch the Search dialog from any activity, and it launches the SearchResultsActivity
.
I would now like to be able to search for images when the user is an ImageListActivity
, using a searchable_images.xml
, and use the default everywhere else.
I have a SearchResultsImageActivity
which includes the following meta-data element, and used the same element in the ImageListActivity
.
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable_images"/>
On pressing the search button in the ImageListActivity
, I get the default search from searchable_articles.xml
.
If I change the default_searchable
to SearchResultsImageActivity
, the image search is always launched, and the article search is never launched.
If I remove the default_searchable
meta-data element altogether, and add searchable
meta-data only selected activities, no search is launched.
I'm fairly sure this should be possible, but I don't know what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的
Manifest
文件中更新ImageListActivity
活动标记,因此,当您在
ImageListActivity
中触发本机搜索时,它将调用SearchResultsImageActivity
> 并为其他人默认一个。假设
SearchResultsImageActivity
是可搜索
。In your
Manifest
file update theImageListActivity
activity tagSo when you will trigger native search in
ImageListActivity
it will invoke theSearchResultsImageActivity
and default one for others.Assuming
SearchResultsImageActivity
issearchable
.我这样做的一种方法是创建假活动,然后在需要时关闭这些活动。
创建两个为子活动命名的类。
然后在单击组件时创建这样的意图...
并在单击按钮或单击其他组件时从 onClick 调用意图:
One way I did this was to create fake activities then switch out the activities when you need them.
Create two class that are named for the sub activities.
then create intents like this when component is clicked...
and call the intents from onClick when a button is clicked or some other component is click:
如果您仅在该活动中覆盖搜索功能,它应该会阻止搜索调用上升到应用程序级别。返回值控制调用是否向上传播。
If you override the search function in just that activity, it should prevent the search call from going up to the application level. The return value controls if the call is propagated up.