如何打开搜索界面?
我一直在非常仔细地关注 可搜索字典 示例,因为我尝试在我的应用程序中实现搜索功能。现在,当我按下搜索按钮时,我似乎无法打开搜索界面。我已将以下内容添加到我的清单中,并将 searchable.xml 资源添加到我的 res 文件夹中(我几乎是从示例中复制的)。
<activity android:name=".main.SearchActivity"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<meta-data android:name="android.app.default_searchable"
android:value=".main.SearchActivity" />
我不明白的是我还需要做什么才能让它发挥作用?有什么我应该硬编码的吗?多谢!
I've been following the Searchable Dictionary example pretty carefully as I'm trying to implement the search functionality in my app. Right now I simply can't seem to get the Search interface to open when I press the search button. I've added the following into my manifest and searchable.xml resource into my res folder (which I pretty much copied from the example).
<activity android:name=".main.SearchActivity"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<meta-data android:name="android.app.default_searchable"
android:value=".main.SearchActivity" />
What I'm not understanding is what else do I need to do to get this to work? Is there something I should have hard coded? Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,我意识到在 searchable.xml 中,您不能使用静态字符串,它们必须来自 strings.xml 资源。我只需创建
search_label
和search_hint
并在 searchable.xml 文件中引用它们。这是原始的文章Nevermind, I realized that in the searchable.xml, you can't use static strings, they have to be from the strings.xml resource. I just had to create
search_label
andsearch_hint
and refer to them in the searchable.xml file. Here's the original article on that.