GithubHelp home page GithubHelp logo

0359xiaodong / progress-button Goto Github PK

View Code? Open in Web Editor NEW

This project forked from trikke/progress-button

0.0 2.0 0.0 624 KB

A button that shows custom drawables when entering a loading state.

License: Apache License 2.0

progress-button's Introduction

Progress Button

A Button which show an animated drawable when it is in a loading state. Could be abused for a lot of other things, but it was mainly created as a way to have a button show it is waiting for something asynchronously. You define loadingdrawables (which can be anything) and when the button enters the loading state, the drawables are switched, until the button leaves this state.

This library contains a few examples and also a < rotate > drawable as an example on how to create some kind of spinner.

Define it in your layout:

<com.trikke.progress.widget.ProgressButton
			android:id="@+id/button"
			android:layout_width="wrap_content"
			android:drawablePadding="15dp"
			android:drawableLeft="@drawable/icon"
			android:layout_height="wrap_content"
			android:text="@string/pressme"
			app:loadingText="@string/loading"
			app:autoDisableClickable="true"
			app:loadingDrawableRight="@drawable/spinner"/>

Don't forget to add the stylable element to attrs.xml

<declare-styleable name="ProgressButton">
		<attr name="loadingDrawableLeft" format="reference" />
		<attr name="loadingDrawableTop" format="reference" />
		<attr name="loadingDrawableRight" format="reference" />
		<attr name="loadingDrawableBottom" format="reference" />
		<attr name="loadingText" format="reference|string" />
		<attr name="loading" format="reference|boolean" />
		<attr name="autoDisableClickable" format="reference|boolean"/>
	</declare-styleable>

You define it as a normal button, except there are extra parameters:

parameter purpose
loadingText text to show while in loading state
autoDisableClickable automatically disable "clickable" when entering the loading state
loadingDrawable[position] define a loading drawable at this position ( left, top, right, bottom)
loading immediately set the button in a state

Enable / disable the progress animation:

...
// switch to the loading state, changes the text and shows the loading drawables
progressButton.enableLoadingState();

// switch to the default state, with default drawables and text
progressButton.disableLoadingState();
...

Download

Just clone this repository and use as you see fit. If you've fixed something or added a feature, be so kind to make a pull request.

progress-button's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.