I want to change image in fab button during transition, but i haven't found how to do it with xml because CustomAttribute tag supports only drawable colors as values. My solution is to set TransitionAdapter to MotionLayout and change drawable in onTransitionChange function.
motionLayout.setTransitionListener(object : TransitionAdapter() {
var fromStart = true
var wasChanged = false
override fun onTransitionChange(
motionLayout: MotionLayout?,
startId: Int,
endId: Int,
progress: Float
) {
if (!wasChanged) {
if (fromStart && progress >= 0.5f) {
fab.setImageResource(R.drawable.ic_done_black_24dp)
wasChanged = true
}
if (!fromStart && progress <= 0.5f) {
fab.setImageResource(R.drawable.ic_add_black_24dp)
wasChanged = true
}
}
}
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
wasChanged = false
fromStart = !fromStart
}
})
But in this case image changes immediately. Is there any way to make the transition smooth like in regular transition in MotionLayout?