startDrag方法已过时,无法编译该程序 [英] startDrag method Deprecated and unable to compile the program
问题描述
不推荐使用startDrag(android.content.ClipData,android.view.View.DragShadowBuilder,java.lang.Object,int)
。如何解决这个问题而不失去与旧版本的兼容性?还有其他选择吗?我正在学习机器人基础知识,在尝试简单的拖放练习时,我遇到了这个错误。
startDrag(android.content.ClipData, android.view.View.DragShadowBuilder, java.lang.Object, int)
is deprecated. How to solve this without losing compatibility to the older versions? Are there any alternatives? I'm learning android basics and while trying out a simple drag and drop exercise, I encountered this error.
推荐答案
根据Androids API参考 startDrag()
在API级别24中已弃用
According to Androids API reference startDrag()
was deprecated in API level 24
使用 startDragAndDrop()
。
由于Android API等级24等于Android N,您可以使用:
And since Android API level 24 equals Android N you can use:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
view.startDragAndDrop(...);
} else {
view.startDrag(...);
}
这篇关于startDrag方法已过时,无法编译该程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!