Android:使搜索在整个应用程序中可用

标签 android search manifest

现在我正在添加

<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/

相关文章:

java - 来自 java.util.zip.Inflater.init(Native Method) 的奇怪 java.lang.OutOfMemoryError

android - 如何在 Android 中使用 CheckBox 跟踪 ListView 中选中的行

android - 从 StartActivityForResult 打开相同的 Activity 返回

android - BaseAdapter NotifyDatasetChanged() getView() 不工作

android - 移动到 Android Annotations v.2.7 后的 java.lang.ArrayStoreException : sun. reflect.annotation.TypeNotPresentExceptionProxy

javascript - 算法和 React - searchFunction

java - JAVA 中 Streaming API 的最佳搜索算法

android - 支持的设备数量差异

java - 无法加载主类 list Lucene Spellchecker

arrays - 如何使用 MATLAB 返回包含 list1 和 list2 中的元素的列表