How to create Custom Swipe Button in Android | Android Studio | Java

In this tutorial, we will see how to create a custom swipe button in android. It allows the user to make an appropriate action without significantly having to confirm his/her intentions because it is hard to swipe the button by accident (But please remember: It is not impossible. So take care!). So you have a much more intuitive, and simpler UX.

Part 1: Add the dependency

Add the dependency in the build.gradle App file

Part 2: Define the XML files

Our swipe button has a circle moving part and a rounded background. So let’s make those parts:

the circle, shape_button.xml

the background, shape_background.xml

The radius can be any number that is very, you can use your radius so the borders are a semi-circle. You can use different colors if you prefer.

Now, in the main XML file define the swipe button and add custom attributes in the swipe button.


here, app:button_image_disabled=”@drawable/adjust” is the initial image when we do not apply swipe in the button, and app:button_image_enabled=”@drawable/check” is the final image when we apply the swipe in the button. See the below figure.

Part 3: Define the Swipe button in the main Java file

now define the swipe button in the main java file, use setOnStateChangeListener in the swipe button to change the state.

Part 4: Output of the Custom Swipe Button

Hi everyone, myself Golap an Android app developer with UI/UX designer.