[Tutorial] Android Process Button - Animated Buttons on Android Studio
In this post, I’ll show you how to use Android Process Button. This is one of my favorite components because this allows you to add animated buttons with progress meters on Android.
I - About Android Tutorials
I’ll be creating a big number of Android tutorials, showing you how to use nice libraries, UI, tips, and more.
I’ll be using Android Studio and Gradle in all tutorials.
If you need some help with any Android lib or feature, feel free to comment here and if possible, I can write a new tutorial about it :)
II - Android Process Button
This library is very simple, and with it you can add something extra to your application and make it more elegant.
You can check the project repository here:
And the project documentation
III - Creating a new project
Now, let’s start to work with it. Start a new Android Studio project.
Create your app with a Blank Activity, called MainActivity.
Now you can add the Android Process Button as a project dependency. Open the
(from module: App).
This is my gradle dependencies:
In this post I’ll show you the components available in this library.
IV - Flat Button
Flat Button is a simple stylish button that you can use in your application.
and add the following code:
This is using a LinearLayout, but feel free to use any layout. The important part if the button declaration,
. As you can see, the button declaration is quite similar with the native Android Button. Here we have two new fields:
, color of the button,
, color of the button when pressed.
Check all attributes here: https://github.com/dmytrodanylyk/android-process-button/wiki/API
You can build and run your application now. If you get any error, post here that I can try to help you.
V - Process Button
This button extends the Flat Button used above and adds a progress behavior. You can set the progress status, a number between 0 and 100.
The process button has four states:
- Normal: progress = 0
- Loading: progress [1, 99]
- Success: progress = 100
- Error: -1
You can configure different colors to each state, and have a loading animation between 1 and 99.
Again, go to your
and add the following code(you can add after the Flat Button):
Check that now we have some new attributes.
We control it using Java. Open your MainActivity, and add the following code in the end of
VI - Submit Process Button
This is very similar with the process button, but you’ll see the difference in the loading animation.
Add the button xml (this is the same xml used to ActionProcessButton, just changed the id!):
the java code is very similar, but now we cannot set the button mode:
VII - Generate Process Button
Now, this button has is identical to the Submit button, just changing the animation orientation.
and the Java code:
This is the demo app:
You can download the source code and demo apk in the github repo.
That’s it, thanks for reading!