Michal P.
01/25/2024, 11:49 AMMahmoo
01/25/2024, 12:24 PMMahmoo
01/25/2024, 12:25 PMMichal P.
01/25/2024, 12:42 PMMichal P.
01/25/2024, 12:43 PMval colorAnim = ObjectAnimator.ofInt(
binding!!.tvLiveDataSource, "textColor",
Color.argb(255, 173, 255, 0), Color.argb(255, 33, 49, 0)
)
colorAnim.duration = 5000
colorAnim.setEvaluator(ArgbEvaluator())
colorAnim.start()
Michal P.
01/25/2024, 12:46 PMMahmoo
01/25/2024, 12:46 PMZach Klippenstein (he/him) [MOD]
01/25/2024, 4:22 PMMichal P.
01/26/2024, 7:46 AMOleksandr Balan
01/30/2024, 4:44 PMAnimatable
is a more correct API for this case.
Column(
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
// You should create a variable for coroutine scope, because ".snapTo"
// and ".animateTo" are suspend methods
val scope = rememberCoroutineScope()
// Then you need to remember a new "Animatable" instance with some initial value
val color = remember { Animatable(Color(0xFF213100)) }
// To get the current value of the "Animatable" you should use "value" property
Text(
text = "Some Colorful Text",
color = color.value,
)
Button(
onClick = {
// On button click, or on some external event you should launch a new
// coroutine where you snap a color immediately to the Green color and
// then animate the color to the Gray during 5000ms duration
scope.launch {
color.snapTo(Color(0xFFAEFF00))
color.animateTo(
targetValue = Color(0xFF213100),
animationSpec = tween(
durationMillis = 5_000
)
)
}
}
) {
Text(text = "New Message")
}
}
Column(
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
// You should create a variable for coroutine scope, because ".snapTo"
// and ".animateTo" are suspend methods
val scope = rememberCoroutineScope()
// Then you need to remember a new "Animatable" instance with some initial value
val color = remember { Animatable(Color(0xFF213100)) }
// To get the current value of the "Animatable" you should use "value" property
Text(
text = "Some Colorful Text",
color = color.value,
)
Button(
onClick = {
// On button click, or on some external event you should launch a new
// coroutine where you snap a color immediately to the Green color and
// then animate the color to the Gray during 5000ms duration
scope.launch {
color.snapTo(Color(0xFFAEFF00))
color.animateTo(
targetValue = Color(0xFF213100),
animationSpec = tween(
durationMillis = 5_000
)
)
}
}
) {
Text(text = "New Message")
}
}
Michal P.
02/06/2024, 1:09 PM