No se puede usar el valor argb color int en Kotlin?

Cuando quiero animar el textColor de TextView en Kotlin:

 val animator = ObjectAnimator.ofInt(myTextView, "textColor", 0xFF8363FF, 0xFFC953BE) 

este error se produce:

 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!, Int!>!, path: Path!): ObjectAnimator! defined in android.animation.ObjectAnimator public open fun <T : Any!> ofInt(target: TextView!, property: Property<TextView!, Int!>!, vararg values: Int): ObjectAnimator! defined in android.animation.ObjectAnimator public open fun ofInt(target: Any!, propertyName: String!, vararg values: Int): ObjectAnimator! defined in android.animation.ObjectAnimator public open fun ofInt(target: Any!, xPropertyName: String!, yPropertyName: String!, path: Path!): ObjectAnimator! defined in android.animation.ObjectAnimator public open fun ofInt(vararg values: Int): ValueAnimator! defined in android.animation.ObjectAnimator 

Parece que el valor 0xFF8363FF y 0xFFC953BE no se puede convertir en Int en Kotlin, sin embargo, es normal en Java:

 ObjectAnimator animator = ObjectAnimator.ofInt(myTextView, "textColor", 0xFF8363FF, 0xFFC953BE); 

¿Algunas ideas? Gracias por adelantado.

0xFF8363FF (así como 0xFFC953BE ) es un Long , no un Int .

Tienes que Int a Int explícitamente:

 val animator = ObjectAnimator.ofInt(myTextView, "textColor", 0xFF8363FF.toInt(), 0xFFC953BE.toInt()) 

El punto es que el valor numérico de 0xFFC953BE es 4291384254 , por lo que debe almacenarse en una variable Long . Pero el bit alto aquí es un bit de signo, que denota un número negativo: -3583042 que puede almacenarse en Int .

Y esa es la diferencia entre dos idiomas. En Kotlin debe añadir el signo - para denotar negativa Int que no es cierto en Java :

 // Kotlin print(-0x80000000) // >>> -2147483648 (fits into Int) print(0x80000000) // >>> 2147483648 (does NOT fit into Int) // Java System.out.print(-0x80000000); // >>> -2147483648 (fits into Integer) System.out.print(0x80000000); // >>> -2147483648 (fits into Integer) 
  • Kotlin: delegado de propiedad anulable observable
  • Cómo setOnEditorActionListener con Kotlin
  • Android Studio 3.0 Canary 1: Las pruebas de Kotlin o las pruebas de Java referentes a las clases de Kotlin fallan
  • Cómo utilizar fragmentos con kotlin
  • ¿Qué es "implementación" en las dependencias de Kotlin Gradle?
  • La mejor manera de combinar banderas enteras con Kotlin?
  • ¿Hay alguna manera de reutilizar una instancia de Job?
  • Deshabilitar la generación incremental para kapt
  • ¿Cuáles son las clases comunes de la plataforma en Kotlin?
  • Archivo Kotlin vs Clase. ¿Cual es la diferencia?
  • Sabor del producto: Clase duplicada encontrada
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.