Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
LoadingButton in Android
Next article icon

LoadingButton in Android

Last Updated : 06 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Android, LoadingButton provides us an amazing UI and an animation whenever the user taps on it. It is very easy to add a LoadingButton in an app. It is very much similar to Button in android, just add the dependency and a few properties. Tags like BL_backgroundColor, BL_circleColor, BL_circleColorSecond, BL_stateShow and many more can be used to customize the Loading Button.

Loading Button View is used wherever the developer wants the user to wait for some time. We can also use Progress Bar instead of this but Loading Button provides unique and attractive UI and increases the user experience. It also provides full control to Developer as it can be customized according to the requirements.

Approach:

Step 1: Add the support Library in your root build.gradle file (not your module build.gradle file). This library jitpack is a novel package repository. It is made for JVM so that any library which is present in github and bitbucket can be directly used in the application. 

build.gradle:

XML
allprojects {             repositories {                    maven { url 'https://jitpack.io' }                 }           }   


Step 2: Add the support Library in build.gradle file and add dependency in the dependencies section. 


XML
dependencies {          //For Snackbar      implementation 'com.google.android.material:material:1.1.0'                 //For LoadingButton     implementation 'com.github.andreasagap:LoadingButtonLibrary:v1.0' }           


Step 3: Add the following code in activity_main.xml file. In this file we add our LoadingButton to the layout. 

activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:id="@+id/root"     android:layout_height="match_parent">      <andreasagap.loadingbutton.ButtonLoading         android:id="@+id/loadingbutton"         android:layout_width="200dp"         android:layout_height="50dp"         android:padding="6dp"         app:BL_backgroundColor="#9c9b9999"         app:BL_circleColor="#219806"         app:BL_circleColorSecond="#126300"         app:BL_enable="true"         app:BL_stateShow="normal"         app:BL_text="Buy Course"         app:BL_textColor="#FFF"         app:BL_textSize="16sp"         android:textStyle="bold"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent" />  </androidx.constraintlayout.widget.ConstraintLayout> 


Step 4: Add the following code in the MainActivity.java file. In this file, attach Loading Button to the root layout then add a Listener to it. So whenever the user taps on it, setOnButtonLoadingListener gets invoked automatically. Inside the listener, three methods are present onClick(), onStart() and onFinish(). Inside the onClick method add the code that should be executed when the button is clicked, in onStart() method add the code that is to be executed immediately when the button is clicked and in onFinish() method add the code that is executed after the other two functions are executed. 

MainActivity.java
package org.geeksforgeeks.loadingbutton            import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import android.os.Bundle; import android.widget.Toast; import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.Snackbar; import andreasagap.loadingbutton.ButtonLoading;  public class MainActivity extends AppCompatActivity {     ButtonLoading loading_button;     ConstraintLayout layout;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          layout = findViewById(R.id.root);         loading_button =findViewById(R.id.loadingbutton);         loading_button.setRoot(loading_button,this, layout);          //set OnClickListener to button         loading_button.setOnButtonLoadingListener(                 new ButtonLoading.OnButtonLoadingListener() {             @Override             public void onClick() {             }             @Override             public void onStart() {                 Toast.makeText(MainActivity.this,                         "Loading Start", Toast.LENGTH_LONG).show();             }             @Override             public void onFinish() {                 //show snackbar when loading finished                 Snackbar.make(layout, "Thank you for                         buying our Course!",                         BaseTransientBottomBar                        .LENGTH_LONG)                        .show();             }         });     }      @Override     public void onBackPressed() {         loading_button.cancel();     } } 

Output:

Reference: https://github.com/andreasagap/LoadingButtonLibrary


Next Article
LoadingButton in Android

M

madhavmaheshwarimm20
Improve
Article Tags :
  • Android
  • Android-Button
  • Java-Android

Similar Reads

    RadioButton in Android
    RadioButton is a widget used in android which provides functionality to choose a single option from multiple sets of options. This is generally used when we want the user to select only one option from the set of given options. In this article, we will take a look at How to use Radio Buttons on Andr
    3 min read
    ToggleButton in Android
    ToggleButton is used to allow users to perform two operations on a single button. These are used to perform on and off operations like that of Switch. ToggleButton can perform two different operations on clicking on it. In this article, we will take a look at How to implement ToggleButton in Android
    4 min read
    Button in Android
    In Android applications, a Button is a user interface that is used to perform some action when clicked or tapped. It is a very common widget in Android and developers often use it. This article demonstrates how to create a button in Android Studio.Class Hierarchy of the Button Class in Kotlinkotlin.
    3 min read
    Sliding Toggle Button in Android
    In this article, we are going are build a very simple and interesting app "SlidingToggleButton" in Android Studio. Android Studio is really a great platform for app designing. We can use both Java and Kotlin Language for programming in Android Studio but note that we will be using java for our app d
    7 min read
    PopView in Android
    In this article, PopView is added to android. When users tap on the view a pop animation with a circular dust effect will appear. A new view can also appear after the popping of the older view. PopView can be used to hide the view or change the view. It makes the user interface more attractive. Supp
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences