新增搜尋功能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
試試 Compose 的方式
Jetpack Compose 是 Android 推薦的 UI 工具包。瞭解如何在 Compose 中新增搜尋功能。
Android 內建的搜尋功能可讓應用程式輕鬆為所有使用者提供一致的搜尋體驗。在應用程式中實作搜尋功能的方式有兩種,取決於裝置上執行的 Android 版本。本文說明如何使用 SearchView
新增搜尋功能,同時透過系統的預設搜尋對話方塊,維持與舊版 Android 的回溯相容性。
課程
- 設定搜尋介面
- 瞭解如何在應用程式中新增搜尋介面,以及如何設定活動來處理搜尋查詢。
- 儲存及搜尋資料
- 瞭解如何在 SQLite 虛擬資料庫資料表中,以簡單的方式儲存及搜尋資料。
- 保持回溯相容性
- 瞭解如何讓搜尋功能與舊版裝置相容。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間: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."]]