Home > Software design >  How to apply Blink animation on Checkbox text color
How to apply Blink animation on Checkbox text color

Time:03-05

I have a blinking method, but this only works for the whole checkbox. I just want to blink the text inside the checkbox. Anyone know how to do this? And also, how can I change the text color when blinking?

Blink code:

fun View.blink(
        times: Int = Animation.INFINITE,
        duration: Long = 300L,
        offset: Long = 100L,
        minAlpha: Float = 0.0f,
        maxAlpha: Float = 1.0f,
        repeatMode: Int = Animation.REVERSE
    ) {
        startAnimation(AlphaAnimation(minAlpha, maxAlpha).also {
            it.duration = duration
            it.startOffset = offset
            it.repeatMode = repeatMode
            it.repeatCount = times
        })
    }

and then in the checkbox:

checkBoxText.blink(3)

CodePudding user response:

You can animate the textColor, it will not affect the box. Here is example to blink the red text

val colorAnimator = ObjectAnimator.ofInt(
    myCheckBox,
    "textColor",
    Color.argb(255, 255, 0, 0), Color.argb(0, 255, 0, 0)
)
colorAnimator.setEvaluator(ArgbEvaluator())
colorAnimator.repeatCount = 3
colorAnimator.duration = 2000
colorAnimator.start()
  • Related