Open In App

Liquid Button in Android

Improve
Improve
Like Article
Like
Save
Share
Report

In this article we are going to implement a liquid button library, This can be used to show animation on a button. When a user completed a course or completes Filling all the details on a form successfully, then we can show this liquid button to show success in a good way. Let’s see the implementation of this feature. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Liquid Button in Android

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add dependency

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.   

compile ‘com.gospelware.liquidbutton:liquidButtonLib:1.1.5’

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 

XML




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
  
    <com.gospelware.liquidbutton.LiquidButton
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
  
</RelativeLayout>


Step 4: Working with the MainActivity.java file

Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. 

Java




import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
  
import androidx.appcompat.app.AppCompatActivity;
  
import com.gospelware.liquidbutton.LiquidButton;
  
public class MainActivity extends AppCompatActivity {
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final LiquidButton liquidButton = findViewById(R.id.button);
        liquidButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LiquidButton btn = (LiquidButton) view;
                btn.startPour();
                btn.setFillAfter(true);
                btn.setAutoPlay(true);
            }
        });
        liquidButton.setPourFinishListener(new LiquidButton.PourFinishListener() {
            @Override
            public void onPourFinish() {
                Toast.makeText(MainActivity.this, "Finish", Toast.LENGTH_SHORT).show();
            }
  
            @Override
            public void onProgressUpdate(float progress) {
                liquidButton.changeProgress(progress);
            }
        });
    }
}


Output:



Last Updated : 06 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads