How to blink button on Android.

Asked

Viewed 1,441 times

1

Hi, I’d like to make a button(Button) flash on Android.

  • 4

    What do you mean by "blink"? It can be background color, text color or even show and display the button. Add a few more details to the question.

1 answer

9


Use a Animation to that 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 be stopped 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 reply

Browser other questions tagged

You are not signed in. Login or sign up in order to post.