AndroidLoadingButton

A simple button with a loading state and animations for Android

License

License

GroupId

GroupId

com.github.92tonywills
ArtifactId

ArtifactId

android-loading-button
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

aar
Description

Description

AndroidLoadingButton
A simple button with a loading state and animations for Android
Project URL

Project URL

https://github.com/92tonywills/android-loading-button
Source Code Management

Source Code Management

https://github.com/92tonywills/android-loading-button

Download android-loading-button

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.92tonywills/android-loading-button/ -->
<dependency>
    <groupId>com.github.92tonywills</groupId>
    <artifactId>android-loading-button</artifactId>
    <version>0.1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.92tonywills/android-loading-button/
implementation 'com.github.92tonywills:android-loading-button:0.1.0'
// https://jarcasting.com/artifacts/com.github.92tonywills/android-loading-button/
implementation ("com.github.92tonywills:android-loading-button:0.1.0")
'com.github.92tonywills:android-loading-button:aar:0.1.0'
<dependency org="com.github.92tonywills" name="android-loading-button" rev="0.1.0">
  <artifact name="android-loading-button" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.92tonywills', module='android-loading-button', version='0.1.0')
)
libraryDependencies += "com.github.92tonywills" % "android-loading-button" % "0.1.0"
[com.github.92tonywills/android-loading-button "0.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.android.support » appcompat-v7 jar 23.4.0

Project Modules

There are no modules declared in this project.

Android Loading Button

Two simple buttons with loading states and animations for Android.

Features

  • Easy to install and use.
  • Nice defaults
  • Easy to customize
  • Auto disables button when set to loading
  • Auto selects disabled color
  • Two default layouts and animations to choose from

Installation

Install via gradle by adding the following dependency

compile 'com.github.92tonywills:android-loading-button:0.1.0'

Usage

Include a button in your xml layout

<!-- or com.github.tonywills.loadingbutton.HorizontalLoadingButton -->
<com.github.tonywills.loadingbutton.LoadingButton
    android:id="@+id/loading_button"
    android:layout_width="240dp"
    android:layout_height="120dp"
    <!-- Customization options -->
    style="@style/Widget.AppCompat.Button.Colored" />

The style attribute it not nessessary, but will make the button display like a default android button. On post Lollipop devices, this means it will appear with the Material ripple and elevation changes. The button tints itself correctly with this style.

Customisation

The following attributes are available for you to customize the look of the button

  • buttonBackgroundTint: a colour resource
    • The normal colour of the button. A lighter version of this colour will be used for the disabled loadingButtonState when the button is loading.
  • loadingColor: a colour resource
    • The colour of the progress indicator, on material supporting devices, this will be the pretty Android spinner
  • buttonText: a string resource
    • The text to show

The HorizontalLoadingButton has all the previous attributes plus

  • buttonTextDefault: a string resource
    • replaces buttonText
    • is the text to show when the view is not loading
  • buttonTextLoading: a string resource
    • The text to show when the button is loading
  • loadingPosition: either left or right
    • Which side to place the spinner

A fully customized button could look like this

<com.github.tonywills.loadingbutton.LoadingButton
    android:id="@+id/loading_button"
    android:layout_width="240dp"
    android:layout_height="120dp"
    app:buttonBackgroundTint="@color/primaryColor"
    app:loadingColor="@color/secondaryColor"
    app:buttonText="Go"
    style="@style/Widget.AppCompat.Button.Colored" />

Be sure to inculde xmlns:app="http://schemas.android.com/apk/res-auto" at the top of your file to access the custom attributes.

Animations

The button includes a default animation to move the text out and the spinner in. To customise this animation, subclass the button and override the animateToState method. See the library source to see an example animation.

Two Variants

The only difference in the two variants (LoadingButton and HorizontalLoadingButton) is the layout. This means the animations are different, too. Check out the example app to see them in action.

Example App

Take a look at the example app to see how to use the button.

Versions

Version
0.1.0
0.0.1