Skip to content

Repository files navigation

Material Loading Button

An Android Material Design button with a built-in loading/progress state. Perfect for showing in-progress feedback on actions like form submission, sign-in, and API calls without building a custom layout.

Android Kotlin minSdk


Features

  • Built-in progress indicator — a loading spinner that appears inside the button while work is happening.
  • Fully customizable — set text, corner radius, and colors to match your app.
  • Ripple + state backgrounds — Material-compatible touch feedback and pressed/disabled states.
  • Lightweight — a single custom View (extends RelativeLayout), no external UI framework required.
  • Kotlin + AndroidX — modern, minimal dependencies (appcompat, core-ktx, material).

Installation

Add the dependency to your module's build.gradle:

dependencies {
    implementation 'com.github.anangkur:Material-Loading-Button:<version>'
}

Published distribution is via JitPack (see the release tags on GitHub for available versions).

Usage

Add the button to your XML layout:

<com.anangkur.materialloadingbutton.MaterialLoadingButton
    android:id="@+id/btnSubmit"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:text="Submit"
    app:radius="8dp" />

Control the loading state from Kotlin

val button = findViewById<MaterialLoadingButton>(R.id.btnSubmit)

// Show the loading spinner (e.g. before an async call)
button.showProgress()

// ... do async work ...

// Hide the spinner and return to normal state
button.hideProgress()

// Set / update the button label
button.setText("Retry")

Available API

Method Description
showProgress() Show the built-in loading spinner.
hideProgress() Hide the loading spinner.
setText(text: String) Update the button label.
setRadius(radius: Float) Adjust the corner radius of the button background.

XML attributes

Attribute Type Description
app:text string The button label.
app:radius dimension Corner radius of the button background.
(color/background attributes) Inherits appcompat/material theming for colors and ripple.

How it works

MaterialLoadingButton extends RelativeLayout and inflates the loading_button layout, which composes a TextView (the label) and a ProgressBar (the spinner). Ripple, state-list, and gradient drawables are generated programmatically in setupBackground(), so the button responds correctly to touch and disabled states while supporting API 16+.

Requirements

  • minSdk 16
  • compileSdk 34
  • Kotlin (JVM target 11)
  • AndroidX (android.useAndroidX=true)

Library module

The reusable library source lives in the materialloadingbutton/ module (an android-library), while app/ is a demo app showing usage.

Contributing

  1. Fork the repository.
  2. Create your feature branch: git checkout -b feature/AmazingFeature.
  3. Commit your changes: git commit -m 'Add some AmazingFeature'.
  4. Push to the branch: git push origin feature/AmazingFeature.
  5. Open a Pull Request.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Anang Kurniawan@anang_kur · anangk97@gmail.com

About

Material Design button with a built-in loading state for Android — show progress feedback in form submission, sign-in, and API calls.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages