Flash or Pulse Animation for a Button Android

At times we may require to get user’s attention to click on a Button, to view some important information in app. For this purpose Flash or Pulse animation helps us very well. Below are code snippets to implement these animations.

Implementing Flash animation

We can use AnimationDrawable class, to add frames of two different colours, which produces flash animation. Below is an example code.

Here im displaying rounded shape button, so i used RoundRectShape class, given radii as argument. If you want a rectangle shape, just replace radii withnull

AnimationDrawable adBtn;

private void applyFlashBackgroundAnimation(){
     float[] radii = new float[8];
     radii[0] = getResources().getDimension(R.dimen.spacing_10);
     radii[1] = getResources().getDimension(R.dimen.spacing_10);
     radii[2] = getResources().getDimension(R.dimen.spacing_10);
     radii[3] = getResources().getDimension(R.dimen.spacing_10);

     radii[4] = getResources().getDimension(R.dimen.spacing_10);
     radii[5] = getResources().getDimension(R.dimen.spacing_10);
     radii[6] = getResources().getDimension(R.dimen.spacing_10);
     radii[7] = getResources().getDimension(R.dimen.spacing_10);
     ShapeDrawable selShape = new ShapeDrawable();
     selShape.setShape(new RoundRectShape(radii, null, null));

     ShapeDrawable defShape = new ShapeDrawable();
     defShape.setShape(new RoundRectShape(radii, null, null));
     adBtn = new AnimationDrawable();
     adBtn.addFrame(selShape, DELAY);
     adBtn.addFrame(defShape, DELAY);
     btnObj.setBackgroundDrawable(adPick);//btnObj is your Button object
     Handler handler== new Handler();
     handler.postDelayed(new Runnable() {
          public void run() {
     }, 100);

//To Stop Animation, simply use stop method of AnimationDrawable object as below.
private void stopFlashAnimation()

Implementing Pulse animation

To produce Pulse or Heartbeat animation, we use ObjectAnimator class. Below is the example code.

ObjectAnimator objAnim;
private void pulseAnimation(){
    objAnim= ObjectAnimator.ofPropertyValuesHolder(btnObj, PropertyValuesHolder.ofFloat("scaleX", 1.5f), PropertyValuesHolder.ofFloat("scaleY", 1.5f));

//To Stop Animation, simply use cancel method of ObjectAnimator object as below.

private void stopPulseAnimation()

That’s it.

Hope it helps somebody… 🙂

You may also interested in..

Integrate BitBucket Plug-in Android Studio

This BitBucket Plugin removed in Jetbrains website now, so below link not working. Good news is this Plug is not required anymore. You may directly start from Enable VCS step below in Android Studio and then proceed next steps. Or else you may look at another detailed post here.

You can push project to Bit Bucket without using Terminal in Android Studio. To do that you need a Bitbucket plug-in.

Install BitBucket Plug-in

You can download BitBucket plugin from this link. After downloading zip file don’t unzip it. Goto Android Studio, press Ctrl+Alt+S, and search for Plugins in left panel. You will see Plugins tab in right panel.


Click on Install plugin from disk,


Select downloaded BitBucket zip file and Click on Apply,

BitBucket Plug-in

It’ll ask to restart Android Studio. Click Restart button.


Enable VCS

After restarting, Your BitBucket Plug in is installed and ready to use. Now to start Push all your project to BitBucket.

Goto- VCS menu-> and select Enable Version Control Integration.


You’ll be prompted to select Version control system for the project root, here select Git as Bit Bucket uses git system


Now Goto, BitBucket website and Create a new repository with same name as project.


You’ll see Command line syntax to init push code. Just copy the bitbucket origin Url as shown below.


Now Goto AndroidStudio, select project and Git->Add as shown below


And then Commit the changes as shown below.


Enter initial Comment for project and then select Commit and Push as shown below.


Here, You’ll ask to define remote,


Click on it and Enter URL that we copied from Bit Bucket command line syntax.


You’ll be able to Push code to the repository. Click on Push button


Now Go to, Bit bucket website you’ll see project files Committed to your repository.


That’s it. You just Pushed all your Project to Bit bucket without using Terminal window.

Hope it helps somebody.


You may also interested in

Beautiful messages collected



  1. Stay away from anger, it hurts only you.
  2. If you are right then there is no need to get angry, and if you are wrong then you don’t have any right to get angry.
  3. Patience with family is love, Patience with others is respect. Patience with self is confidence and Patience with GOD is faith.
  4. Never think hard about the PAST, It brings tears. Don’t think more about the FUTURE, It brings fears. Live this moment with a smile, it brings cheers.
  5. Every test in our life makes us bitter or better, every problem comes to make us or break us, The choice is ours whether we become victims or victorious.
  6. Beautiful things are not always good but good things are always beautiful.
  7. Do you know why God created gaps between fingers? So that someone who is special to you comes and fills those gaps by holding your hand forever.
  8. Happiness keeps you sweet so try n be as happy from within as possible.
  9. God has sent us all in pairs, someone somewhere is made for u. So wait for the right time n right moment.

copied message 🙂

You may be also interested in


Create new Class extends a SuperClass- Android Studio

In Android studio, If you want to create a new Class extends a SuperClass, built-in menu doesn’t provide option for it.

Create a Class extends a SuperClass

Where as you can only Create a new Class and then manually write down extends Superclass.

Image 1
Image 2

To add Create new Class which extends a SuperClass, you need to Create a new Template

Press Ctrl+Alt+S to open Settings  window, here search for File and Code Templates

Image 3

Click + button to add new template, give a name as Inheritance(you can give any name) and write this below code

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != “”)package ${PACKAGE_NAME};#end
#parse(“File Header.java”)
public class ${NAME} extends ${SUPERCLASS} {

Apply it and the Click Ok button. as shown below

Image 4

Now go to project and try to create new class as shown Image 1 above..

and  you’ll see newly added template in dropdown as shown below.


Select it and then you’ll be asked to enter Super class name. Enter your Super class name.


That’s it.

You’ll see new Class created with SuperClass.

Hope it helps somebody.

You may also interested in


Gradle DSL method not found – Android Studio

After importing Eclipse project to Android Studio. When you run the project, you may see following error message as, Gradle DSL not found: ‘android()’

Gradle DSL

Solution to fix this Gradle DSL method issue

open Top-level build.gradle file of the project


And remove the following code lines.

android {
compileSdkVersion 21
buildToolsVersion '21.1.2'

And then click Sync menu button, fixes the issue.


And another possible issue is,

Gradle DSL method not found: ‘runProguard()’

At times when you import a downloaded sample project in to Android Studio, see following error message as, Gradle DSL not found: ‘runProguard()’


Solution to fix this Gradle DSL method issue

open app’s build.gradle file of the project


In this file you can see following code snippet

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

In the above code runProguard false causing the issue. Change that line to

minifyEnabled false

Now click Sync menu button, issue will be fixed. I see the reason for this is runProguard has been renamed to minifyEnabled in version 0.14.0 or more in Gradle.

Hope it helps somebody. 😎

You may be also interested in