Hello, I would like to make a button ( Button
) flash on Android.
Hello, I would like to make a button ( Button
) flash on Android.
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