Android 应用程序搜索按钮

发布于 2024-08-08 23:40:58 字数 813 浏览 4 评论 0原文

我一直在尝试让我的应用程序实现内置的快速搜索,类似于 ApiDemos 的“app/search/invoke search”中的完成方式。我已经尝试了一切,从尝试遵循不同的示例,到完全按照 ApiDemos 中的方式复制代码。

我对前者的所有发现都与旧版本的 SDK 有关,并且根本不起作用。至于我实际上可以在 ApiDemos 中运行并看到的内容,我尝试复制以下内容

com.example.android.apis.app.SearchInvoke.java
com.example.android.apis.app.SearchQueryResults.java
com.example.android.apis.app.SearchSuggestionSampleProvider.java

res/layout/search_invoke.xml
res/layout/search_query_results.xml
res/values/arrays.xml
res/values/strings.xml
res/xml/searchable.xml

... and everything under "Search Samples" in AndroidManifest.xml

此复制使我看到的视图与运行 ApiDemos 时所面临的视图完全相同,但是当我单击搜索按钮时,在快速搜索框中,Android 始终只打开一个浏览器窗口,其中包含给定查询的 Google 搜索结果。我根本无法在 ApiDemos 中找到告诉 android 我想使用自己的自定义代码来处理搜索请求的关键组件。

我真的很感激在这件事上的一些帮助。在这方面,文档和其他在线资源似乎都非常缺乏。

谢谢。

I've been trying to make my app implement the built in quick search, similar to how it is done in ApiDemos' "app/search/invoke search". I have tried everything from trying to follow different examples, to copying the code exactly as it is in ApiDemos.

All I've found for the former have been concerned with older versions of the SDK, and simply not worked. As for the stuff that I can actually run and see working in ApiDemos, I've tried copying the following

com.example.android.apis.app.SearchInvoke.java
com.example.android.apis.app.SearchQueryResults.java
com.example.android.apis.app.SearchSuggestionSampleProvider.java

res/layout/search_invoke.xml
res/layout/search_query_results.xml
res/values/arrays.xml
res/values/strings.xml
res/xml/searchable.xml

... and everything under "Search Samples" in AndroidManifest.xml

This copying gets me a view that looks exactly like the one I'm facing when running ApiDemos, but when I click the search button, in the quick search box, Android always just opens up a browser window, with Google search results for the given query. I simply cannot find the critical component in ApiDemos that tells android that I want to use my own custom code for handling the search request.

I would really appreciate some help in this matter. Both documentation and other online resources seem very lacking when it comes to this.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小苏打饼 2024-08-15 23:40:58

作为参考,四个月(天知道有多少次尝试)之后,我发现了我错过的文档部分,该部分让整个搜索框表现出启动浏览器搜索结果,而不是将它们传递给我的自己的活动。这一切都归结为此处:

请注意,所有用户可见的字符串都必须以“@string”引用的形式提供。无法本地化的硬编码字符串将无法在搜索元数据中正常工作。

For reference, four months (and god knows how many attempts) later, I've found the part of the documentation I've missed out on, that had the whole search box behave fire up browser search results, instead of passing them to my own activity. It all comes down to a little notice found here:

Note that all user-visible strings must be provided in the form of "@string" references. Hard-coded strings, which cannot be localized, will not work properly in search metadata.

仅此而已 2024-08-15 23:40:58

首先尝试阅读。如果这没有帮助,您可以尝试查看搜索示例 来自我的一本书中——该示例与快速搜索框集成,也许它会给您更多线索。

Try reading this first. If that does not help, you can try looking at the search example from one of my books -- that example integrates with the Quick Search Box, and perhaps it will give you more clues.

梦一生花开无言 2024-08-15 23:40:58

除了commonsware.com提供的示例之外,您还可以查看1.6 SDK的示例目录中的Searchable Dictionary。

http://developer.android.com/guide/samples/SearchableDictionary/index.html html

In addition to the examples provided by commonsware.com, you can look at the Searchable Dictionary in the samples directory of the 1.6 SDK.

http://developer.android.com/guide/samples/SearchableDictionary/index.html

风透绣罗衣 2024-08-15 23:40:58

我之前错了... SDK 文档在文档中对 有详尽的解释我建议你看看SearchManager。此外,正如 CommonsWare 提到的,博客条目也是一个很好的资源。

I was wrong before... the SDK documentation has a thurough explanation in the docs for SearchManager that I suggest you take a look at. In addition, as CommonsWare mentioned, the blog entry is also a good resource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文