使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
拖放
接受来自其他应用或应用内的拖放数据,并显示一致的拖放目标可视效果。
最近更新时间 |
稳定版 |
候选版 |
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")
}
如需详细了解依赖项,请参阅添加 build 依赖项。
反馈
您的反馈将帮助我们改进 Jetpack。如果您发现了新问题,或对此库有任何改进建议,请告诉我们。创建新问题前,请先查看此库中的现有问题。您可以点击星标按钮,为现有问题投票。
创建新问题
如需了解详情,请参阅问题跟踪器文档。
版本 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 数据,当用户放下 ClipData
时,DropHelper
会选择拖放目标中的一个 EditText
元素来处理文本数据。
如需了解详情,请参阅拖放方面的开发者指南。
版本 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 变更
- 默认情况下,具有非 null localState 的 DragEvent 不会触发突出显示效果。您可以通过一个配置选项更改此行为。(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 数据,当用户放下 ClipData
时,DropHelper
会选择拖放目标中的一个 EditText
元素来处理文本数据。
如需了解详情,请参阅拖放方面的开发者指南。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):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."]]