Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.92tonywills:android-loading-button:'
}
dependencies {
implementation("com.github.92tonywills:android-loading-button:")
}
<dependency>
<groupId>com.github.92tonywills</groupId>
<artifactId>android-loading-button</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.92tonywills" % "android-loading-button" % ""
:dependencies [[com.github.92tonywills/android-loading-button ""]]
Two simple buttons with loading states and animations for Android.
Install via gradle by adding the following dependency
compile 'com.github.92tonywills:android-loading-button:0.1.0'
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.
The following attributes are available for you to customize the look of the button
buttonBackgroundTint
: a colour resource
loadingColor
: a colour resource
buttonText
: a string resource
The HorizontalLoadingButton
has all the previous attributes plus
buttonTextDefault
: a string resource
buttonText
buttonTextLoading
: a string resource
loadingPosition
: either left
or right
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.
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.
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.
Take a look at the example app to see how to use the button.