How to make button blink on Android. [closed]

1

Hello, I would like to make a button ( Button ) flash on Android.

    
asked by anonymous 29.01.2015 / 15:11

1 answer

10

Use Animation to achieve this effect

private Animation animation;
private Button btn;

public void onCreate(Bundle savedInstanceState) {
    animation = new AlphaAnimation(1, 0); // Altera alpha de visível a invisível
    animation.setDuration(500); // duração - meio segundo
    animation.setInterpolator(new LinearInterpolator());
    animation.setRepeatCount(Animation.INFINITE); // Repetir infinitamente
    animation.setRepeatMode(Animation.REVERSE); //Inverte a animação no final para que o botão vá desaparecendo
    btn = (Button) findViewById(R.id.your_btn);
    btn.startAnimation(animation);

}  

If you want the animation to stop after the button is clicked:

btn.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(final View view) {
        view.clearAnimation(); //Pára a animação
    }
}); 

To start the animation again, do: btn.startAnimation(animation);

Adapted from this response

    
29.01.2015 / 15:41