添加搜索功能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
试试 Compose 方式
Jetpack Compose 是推荐用于 Android 的界面工具包。了解如何在 Compose 中添加搜索功能。
借助 Android 的内置搜索功能,应用可以轻松为所有用户提供一致的搜索体验。在应用中实现搜索的方法有两种,具体取决于设备搭载的 Android 版本。本文档介绍了如何使用系统的默认搜索对话框添加 SearchView
搜索功能,同时保持与较低版本的 Android 之间的向后兼容性。
课程
- 设置搜索界面
- 了解如何向您的应用添加搜索界面,以及如何配置 activity 来处理搜索查询。
- 存储和搜索数据
- 了解如何轻松在 SQLite 虚拟数据库表格中存储和搜索数据。
- 保持向后兼容性
- 了解如何让搜索功能与旧设备后向兼容。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Add search functionality\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to add search functionality in Compose. \n[Filter a list →](/develop/ui/compose/quick-guides/content/filter-list-while-typing) \n\nAndroid's built-in search features offer apps an easy way to provide a\nconsistent search experience for all users. There are two ways to implement search in your app,\ndepending on the version of Android that is running on the device. This documentation covers how\nto add search with\n[SearchView](/reference/android/widget/SearchView) while maintaining\nbackward compatibility with older versions of Android by\nusing the system's default search dialog.\n\nLessons\n-------\n\n**[Set up the search interface](/develop/ui/views/search/training/setup)**\n: Learn how to add a search interface to your app and how to configure an activity to handle\n search queries.\n\n**[Store and search for data](/develop/ui/views/search/training/search)**\n: Learn a simple way to store and search for data in a SQLite virtual database table.\n\n**[Remain backward compatible](/develop/ui/views/search/training/backward-compat)**\n: Learn how to keep search features backward compatible with older devices."]]