
val animator = ObjectAnimator.ofInt(myTextVIEw,"textcolor",0xFF8363FF,0xFFC953BE)
发生此错误:
Error:(124,43) None of the following functions can be called with the arguments supplIEd:public open fun <T : Any!> ofInt(target: TextVIEw!,xProperty: Property<TextVIEw!,Int!>!,yProperty: Property<TextVIEw!,path: Path!): ObjectAnimator! defined in androID.animation.ObjectAnimatorpublic open fun <T : Any!> ofInt(target: TextVIEw!,property: Property<TextVIEw!,vararg values: Int): ObjectAnimator! defined in androID.animation.ObjectAnimatorpublic open fun ofInt(target: Any!,propertyname: String!,xPropertyname: String!,yPropertyname: String!,path: Path!): ObjectAnimator! defined in androID.animation.ObjectAnimatorpublic open fun ofInt(vararg values: Int): ValueAnimator! defined in androID.animation.ObjectAnimator
似乎在Kotlin中不能将值0xFF8363FF和0xFFC953BE强制转换为Int,但是,它在Java中是正常的:
ObjectAnimator animator = ObjectAnimator.ofInt(myTextVIEw,0xFFC953BE);
有任何想法吗?提前致谢.
解决方法 0xFF8363FF(以及0xFFC953BE)是Long,而不是Int.你必须明确地将它们转换为Int:
val animator = ObjectAnimator.ofInt(myTextVIEw,0xFF8363FF.toInt(),0xFFC953BE.toInt())
关键是0xFFC953BE的数值是4291384254,因此它应该存储在Long变量中.但这里的高位是符号位,表示负数:-3583042,可以存储在Int中.
这就是两种语言之间的区别.在Kotlin中你应该添加 – 符号来表示负的Int,这在Java中是不正确的:
// Kotlinprint(-0x80000000) // >>> -2147483648 (fits into Int)print(0x80000000) // >>> 2147483648 (does NOT fit into Int)// JavaSystem.out.print(-0x80000000); // >>> -2147483648 (fits into Integer)System.out.print(0x80000000); // >>> -2147483648 (fits into Integer)总结
以上是内存溢出为你收集整理的android – 在Kotlin中不能使用argb color int值吗?全部内容,希望文章能够帮你解决android – 在Kotlin中不能使用argb color int值吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)