透過集合功能整理內容
你可以依據偏好儲存及分類內容。
DragAndDrop
接受來自其他應用程式或應用程式之中的拖曳資料,並顯示一致的放置目標預設用途。
最近更新時間 |
穩定版 |
候選版 |
Beta 版 |
Alpha 版 |
2022 年 5 月 11 日 |
1.0.0 |
- |
- |
- |
宣告依附元件
如果要為 DragAndDrop 新增依附元件,您必須將 Google Maven 存放區新增至專案。詳情請參閱「Google 的 Maven 存放區」。
在應用程式或模組的 build.gradle
檔案中,新增所需構件的依附元件:
Groovy
dependencies {
implementation "androidx.draganddrop:draganddrop:1.0.0"
}
Kotlin
dependencies {
implementation("androidx.draganddrop:draganddrop:1.0.0")
}
如要進一步瞭解依附元件,請參閱「新增建構依附元件」一文。
意見回饋
您的意見可協助我們改善 Jetpack。如果您發現新問題,或是有改進這個程式庫的建議,請告訴我們。回報新問題前,請先查看這個程式庫的現有問題。只要按一下星號按鈕,即可投票給現有的問題。
建立新問題
詳情請參閱 Issue Tracker 說明文件。
1.0 版
1.0.0 版本
2022 年 5 月 11 日
發布 androidx.draganddrop:draganddrop:1.0.0
。1.0.0 版包含此連結所列的修訂項目。
1.0.0 的主要功能
DropHelper
是 draganddrop
程式庫的第一個成員,可簡化拖曳功能的實作。使用 DropHelper
來指定放置目標、自訂放置目標醒目顯示,以及定義系統如何處理放置的資料。
DropHelper
運用 Jetpack 的 OnReceiveContentListener
提供拖曳 ClipData
的目標專屬處理功能。DropHelper
會在使用者拖曳內容經過目標時,設定醒目顯示的放置目標,藉此提升使用者體驗。DropHelper.Options
巢狀類別可讓您自訂預設醒目顯示的外觀。
DropHelper
會將 OnReceiveContentListener
附加至放置目標,並設定放置目標來監聽拖曳事件。使用 DropHelper
時,請勿將 OnDragListener
或其他 OnReceiveContentListener
附加至放置目標。
DropHelper.Options
還會提供相關功能,讓您列出複合式放置目標檢視區塊階層中包含的所有 EditText
元素。如果有的話,則必須以這種方式指明。DropHelper
會防止 EditText
元素在使用者拖曳資料經過目標時,從放置目標上奪走焦點。如果拖曳 ClipData
含有文字和 URI 資料,DropHelper
會選取放置目標的其中一個 EditText
元素,在放下 ClipData
時處理文字資料。
如需詳細資訊,請參閱拖曳開發人員指南。
1.0.0-rc01 版
2022 年 4 月 20 日
發布 androidx.draganddrop:draganddrop:1.0.0-rc01
。1.0.0-rc01 版包含以下修訂項目。
1.0.0-beta01 版本
2022 年 3 月 23 日
發布 androidx.draganddrop:draganddrop:1.0.0-beta01
。1.0.0-beta01 版本包含這些修訂版本。
1.0.0-alpha04 版本
2022 年 2 月 23 日
androidx.draganddrop:draganddrop:1.0.0-alpha04
發布。查看 1.0.0-alpha04 版的修訂項。
API 相關異動
- 根據預設,包含非空值 localState 的 DragEvents 不會觸發醒目顯示。有一個設定選項可以變更這項行為 (I55792)。
1.0.0-alpha03 版本
2022 年 1 月 26 日
androidx.draganddrop:draganddrop:1.0.0-alpha03
發布。1.0.0-alpha03 版包含以下修訂項目。
新功能
- 在搭載 Android S 以上版本的裝置上,
DropHelper
現在委派給 OnReceiveContentListener
的系統實作,會自動支援拖曳以外的輸入方法。
1.0.0-alpha02 版本
2021 年 12 月 15 日
androidx.draganddrop:draganddrop:1.0.0-alpha02
發布。1.0.0-alpha02 版本包含這些修訂版本。
初始版本中的功能
DropHelper
是 draganddrop
程式庫的第一個成員,可簡化拖曳功能的實作。使用 DropHelper
來指定放置目標、自訂放置目標醒目顯示,以及定義系統如何處理放置的資料。
DropHelper
運用 Jetpack 的 OnReceiveContentListener
提供拖曳 ClipData
的目標專屬處理功能。DropHelper
會在使用者拖曳內容經過目標時,設定醒目顯示的放置目標,藉此提升使用者體驗。DropHelper.Options
巢狀類別可讓您自訂預設醒目顯示的色彩和圓角半徑。
此外,DropHelper.Options
還會提供相關功能,讓您列出複合式放置目標檢視區塊階層中收納的所有 EditText
元素。DropHelper
會防止 EditText
元素在使用者拖曳資料經過目標時,從放置目標上奪走焦點。如果拖曳 ClipData
含有文字和 URI 資料,DropHelper
會選取放置目標的其中一個 EditText
元素,在放下 ClipData
時處理文字資料。
如需詳細資訊,請參閱拖曳開發人員指南。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# DragAndDrop\n===========\n\nAPI Reference \n[androidx.draganddrop](/reference/kotlin/androidx/draganddrop/package-summary) \nAccept drag-and-drop data from another app or within an app, and show a consistent drop target affordance. \n\n| Latest Update | Stable Release | Release Candidate | Beta Release | Alpha Release |\n|---------------|-------------------------------------------------------|-------------------|--------------|---------------|\n| May 11, 2022 | [1.0.0](/jetpack/androidx/releases/draganddrop#1.0.0) | - | - | - |\n\nDeclaring dependencies\n----------------------\n\nTo add a dependency on DragAndDrop, you must add the Google Maven repository to your\nproject. Read [Google's Maven repository](/studio/build/dependencies#google-maven)\nfor more information.\n\nAdd the dependencies for the artifacts you need in the `build.gradle` file for\nyour app or module: \n\n### Groovy\n\n```groovy\ndependencies {\n implementation \"androidx.draganddrop:draganddrop:1.0.0\"\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n implementation(\"androidx.draganddrop:draganddrop:1.0.0\")\n}\n```\n\nFor more information about dependencies, see [Add build dependencies](/studio/build/dependencies).\n\nFeedback\n--------\n\nYour feedback helps make Jetpack better. Let us know if you discover new issues or have\nideas for improving this library. Please take a look at the\n[existing issues](https://issuetracker.google.com/issues?q=componentid:1139019%20status:open)\nin this library before you create a new one. You can add your vote to an existing issue by\nclicking the star button.\n\n[Create a new issue](https://issuetracker.google.com/issues/new?component=1139019&template=1644483)\n\nSee the [Issue Tracker documentation](https://developers.google.com/issue-tracker)\nfor more information.\n\nVersion 1.0\n-----------\n\n### Version 1.0.0\n\nMay 11, 2022\n\n`androidx.draganddrop:draganddrop:1.0.0` is released. [Version 1.0.0 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/792d15289c94ffb5121f8e0ea664cc758926ff49..50f2d1d62c4cb89366df3bf9f811754b8cdda677/draganddrop/draganddrop)\n\n**Major features of 1.0.0**\n\n`DropHelper`, the first member of the `draganddrop` library, is a utility class that simplifies implementation of drag and drop capabilities. Use `DropHelper` to specify drop targets, customize drop target highlighting, and define how dropped data is handled.\n\n- `DropHelper` leverages Jetpack's [`OnReceiveContentListener`](/reference/androidx/core/view/OnReceiveContentListener) to provide target-specific processing of drag and drop [`ClipData`](/reference/android/content/ClipData). `DropHelper` enhances the user experience by configuring drop targets to display a highlight as users drag content over the targets. The `DropHelper.Options` nested class enables you to customize the appearance of the default highlight.\n- `DropHelper` attaches an [`OnReceiveContentListener`](/reference/androidx/core/view/OnReceiveContentListener) to drop targets and configures drop targets to listen for drag and drop events. Do not attach an [`OnDragListener`](/jetpack/androidx/releases/m/reference/android/view/View.OnDragListener) or additional `OnReceiveContentListener` to drop targets when using `DropHelper`.\n- `DropHelper.Options` gives you the ability to list all [`EditText`](/reference/android/widget/EditText) elements contained in the view hierarchy of complex drop targets. If any are present, they must be specified in this way. `DropHelper` prevents the `EditText` elements from stealing focus from the drop target when users drag data over the target. If the drag and drop `ClipData` includes text and URI data, `DropHelper` selects one of the `EditText` elements in the drop target to handle the text data when the `ClipData` is dropped.\n\nFor more information, see the [Drag and drop](/guide/topics/ui/drag-drop#drophelper) developer's guide.\n\n### Version 1.0.0-rc01\n\nApril 20, 2022\n\n`androidx.draganddrop:draganddrop:1.0.0-rc01` is released. [Version 1.0.0-rc01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/5ef5671233460b844828e14a816255dbf7904868..792d15289c94ffb5121f8e0ea664cc758926ff49/draganddrop/draganddrop)\n\n- No changes since the last beta release.\n\n### Version 1.0.0-beta01\n\nMarch 23, 2022\n\n`androidx.draganddrop:draganddrop:1.0.0-beta01` is released. [Version 1.0.0-beta01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/9b2b3d8efd5f00bd4af903bbaa926f6a712d0bd8..5ef5671233460b844828e14a816255dbf7904868/draganddrop/draganddrop)\n\n- No changes since last alpha release.\n\n### Version 1.0.0-alpha04\n\nFebruary 23, 2022\n\n`androidx.draganddrop:draganddrop:1.0.0-alpha04` is released. [Version 1.0.0-alpha04 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/9dceceb54300ed028a7e8fc7a3454f270337ffde..9b2b3d8efd5f00bd4af903bbaa926f6a712d0bd8/draganddrop/draganddrop)\n\n**API Changes**\n\n- DragEvents with a non-null localState will not trigger highlighting by default. There is a configuration option to change this behavior. ([I55792](https://android-review.googlesource.com/#/q/I55792b436b346ed9e5fa092c88b4e878087d1395))\n\n### Version 1.0.0-alpha03\n\nJanuary 26, 2022\n\n`androidx.draganddrop:draganddrop:1.0.0-alpha03` is released. [Version 1.0.0-alpha03 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/301586664b5aad60548f21866cad502d524dbf9f..9dceceb54300ed028a7e8fc7a3454f270337ffde/draganddrop/draganddrop)\n\n**New Features**\n\n- On devices running Android S or later, `DropHelper` now delegates to the system implementation of `OnReceiveContentListener`, automatically providing support for input methods other than drag and drop.\n\n### Version 1.0.0-alpha02\n\nDecember 15, 2021\n\n`androidx.draganddrop:draganddrop:1.0.0-alpha02` is released. [Version 1.0.0-alpha02 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/301586664b5aad60548f21866cad502d524dbf9f/draganddrop/draganddrop)\n\n**Features in initial release**\n\n`DropHelper`, the first member of the `draganddrop` library, is a utility class that simplifies implementation of drag and drop capabilities. Use `DropHelper` to specify drop targets, customize drop target highlighting, and define how dropped data is handled.\n\n`DropHelper` leverages Jetpack's [`OnReceiveContentListener`](/reference/androidx/core/view/OnReceiveContentListener) to provide target-specific processing of drag and drop [`ClipData`](https://developer.android.com/reference/android/content/ClipData). `DropHelper` enhances the user experience by configuring drop targets to display a highlight as users drag content over the targets. The `DropHelper.Options` nested class enables you to customize the color and corner radius of the default highlight.\n\n`DropHelper.Options` also gives you the ability to list all [`EditText`](/reference/android/widget/EditText) elements contained in the view hierarchy of complex drop targets. `DropHelper` prevents the `EditText` elements from stealing focus from the drop target when users drag data over the target. If the drag and drop `ClipData` includes text and URI data, `DropHelper` selects one of the `EditText` elements in the drop target to handle the text data when the `ClipData` is dropped.\n\nFor more information, see the [Drag and drop](/guide/topics/ui/drag-drop) developer's guide."]]