Make a Button Blink Animate in Android Java

Here is java code to animate android button

You can make a button blink or animate in Android java with this simple code, here i chose a toggle button and then set the animation code to make it blink.

You can try different blinking rates by changing the offset value.

ToggleButton btn =findViewById(R.id.img1);// identify your button here


//this is the code to animate, place it under Onclick method so it will blink when button pressed
Animation anim = new AlphaAnimation(0.5f, 1.0f);
            anim.setDuration(50); //You can manage the blinking time with this parameter
            anim.setStartOffset(200);
            anim.setRepeatMode(Animation.REVERSE);
            anim.setRepeatCount(Animation.INFINITE);
            btn.startAnimation(anim);

 

Related Posts

Fix Plugin [id: ‘com.android.application’, version: ‘7.1.3’, apply: false] was not found in any of the following sources

Here is how to fix Plugin [id: ‘com.android.application’, version: ‘7.1.3’, apply: false] was not found in any of the following sources This error is caused by mismatching…

Get Age from Date of Birth in Java Android

Here is how to get a user’s age from date of birth If you need get a user’s age from a given date of birth string, this…

How to Check if String Array Contains a Specific String in Android

Here is how to get a specific value or String from Array in Android To check if a string array contains a specific string, you can use…

Make Android WebView Support Razorpay Payment

How to Support Razorpay Payment and UPI in Android WebView? Android webview is inexpensive and easy way to make apps for websites. But to support some specific…

Make Android Webview Support PayTM Google Pay PhonePe UPI

GooglePay, Phonpe and PayTM support in Android WebView If you have built an android app for your new ecommerce website or any other website that needs accept…

Leave a Reply

Your email address will not be published.