Skip to main content

Twitter Like Button in Android

How to make Twitter like button in Android




Today, we gonna learn how to make like button the same as Twitter has on their website with animation. See the below gif.


Let's get started. First, create a new project in Android Studio if you not created already.

After creating the project, we need to add some dependencies to our project.

So first, open your build.gradle (Project: <app_name>) file and add below line in allprojects repositories section as shown below.


Now after that, we need to open our build.gradle (Module: app) and this dependency.


This is all our dependency part. Now hit the sync now button at the top right corner.

This will add the dependency in our project. 

Now we can move forward and open an activity xml file and this code in our layout for the like button.


Our activity xml file has ConstraintLayout as parent layout so we have to add constraints attributes.

As you can see in our like button we have icon_type attribute has heart value. You can add thumb or star. 

You can customize as per your requirements.

Now after adding the like button in the xml file, we need to add a listener to our like button to know when the button clicked or like and unliked.

To do that, go to your activity java file and add the listener to the like button.


In the above code, we get our like button from xml file using the findViewById method.

After getting the like button we are setting the onLikeListener method which accepts an interface as a callback and implements two methods one is liked method and unLiked method.

In the liked method, we are showing the toast when a user like the button and,

In the unLiked method, we are shoeing toast when the user hits the unlike.


Now run your app and check your app and notice the beautiful animation when you like the button.


Hope you learned something new. If you like this article share it with your friends and mates.

Thank you.

Popular Posts

Customize rating bar in android

Working with Bottom Navigation bar in Android [Full Guide]

Custom Switch in Android | Akshayrana.in | Android Tutorial