现在我正在添加
<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" />
对于 AndroidManifest.xml 中的每一个 <activity>
,在每个 Activity 中接收 Intent
,并将搜索字符串转发到实际执行搜索(通过 HTTP/JSON)并在列表中显示结果的一个 singleTop
Activity 。
我想知道是否有办法设置 AndroidManifest.xml,以便在应用程序内的每个 Activity 中激活搜索,但搜索字符串将从 Android 的搜索框直接转发到我的 singleTop
SearchResults_Activity而不是通过验证每个 Activity 中的事件然后转发搜索字符串。
最佳答案
这个问题的答案实际上可以在 SearchManager 文档中找到,位于 MetaData章。
Activities which are part of a searchable application, but don't implement search itself, require a bit of "glue" in order to cause them to invoke search using your searchable activity as their primary context. If this is not provided, then searches from these activities will use the system default search context.
<application>
<meta-data android:name="android.app.default_searchable"
android:value=".MySearchActivity" />
<!-- followed by activities, providers, etc... -->
</application>
关于Android:使搜索在整个应用程序中可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1707083/