0

image How to get this kind of animation in Android studio. I am creating a quiz app. I want user to click a button and let the code check for answer and then change button animation as in the video.

  • Check this out: [How to make a Button blink in Android?](https://stackoverflow.com/questions/43705249/how-to-make-a-button-blink-in-android) – Doombringer Jun 28 '21 at 03:35

1 Answers1

1

Create a file in res folder with name alpha_animation

  <?xml version="1.0" encoding="utf-8"?>
<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromAlpha="1"
    android:toAlpha="0.05"
    android:repeatCount="5"
    android:repeatMode="reverse"
    />

now write this in you activity

    private Button mButton;
    private Animation mAlphaAnimation;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Get the application context
        mContext = getApplicationContext();
        mActivity = MainActivity.this;

        mButton = (Button) findViewById(R.id.btn);
        mAlphaAnimation =   AnimationUtils.loadAnimation(mContext,R.anim.alpha_animation);

        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Start the blink animation (fade in and fade out animation)
                mButton.startAnimation(mAlphaAnimation);
            }
        });
    }
Devraj
  • 1,479
  • 1
  • 22
  • 42