Button With Progress - Krunal-Kevadiya/kotlin-common GitHub Wiki

  • Almost everybody agrees that a great design helps a lot to make people get interested in you app. If you don't agree, try to publish an app with a awful UI and see what happens…

  • The huge majority of apps in Play Store uses Progress Dialog to show progress, but some high quality apps innovate with nice animations to show the user that he should wait. Let's see how to make a different loading animation: Morph a button into a loading spinner.

How to use

  • Add the button in your layout file and customize it the way you like it.
<com.kotlinlibrary.buttonview.ProgressButton
        android:id="@+id/btn_normal"
        android:layout_width="0dp"
        android:layout_height="@dimen/_50sdp"
        android:gravity="center"
        android:text="@string/btn_normal"
        android:textColor="@color/colorLine"
        app:pb_normal_color="@color/colorAccent"
        app:pb_progress_style="dots"
        app:pb_progress_dots_count="2"
        app:pb_corner_radius="@dimen/_25sdp"
        app:pb_anim_corner_radius="@dimen/_25sdp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

List of Property

Here there are define all property which are available and you have used it.

Property Description
pb_gradient_name In build 168 gradient provided, if you want to used then set name
Ex: app:pb_gradient_name="HappyAcid"
pb_gradient_type Used for apply Effect of gradient like Linear, Radial and Sweep
Ex: app:pb_gradient_type="Linear"
pb_radial_radius This property used for Radial type gradient in set radius of radial gradient
Ex: app:pb_radial_radius="60"
pb_gradient_angle Apply gradient angle, Range 0 to 360
Ex: app:pb_gradient_angle="200"
pb_gradient_colors Set gradient color array
Ex: app:pb_gradient_colors="@array/colors"
<array name="colors">
<item>#008577</item>
<item>#D81B60</item>
<item>#2AB63A</item>
</array>
pb_gradient_positions Set color offset to display which position, Range 0.0 to 1.0
Ex: app:pb_gradient_positions="@array/positions"
<string-array name="positions">
<item>0.0</item>
<item>0.99</item>
<item>1.0</item>
</string-array>
pb_normal_color Used for solid background
Ex: app:pb_normal_color="@color/colorPrimary"
pb_corner_radius Used for rounded corner set
Ex: app:pb_corner_radius="@dimen/_25sdp"
pb_corner_topLeftRadius Apply top left corner in rounded shape and other as it is
Ex: app:pb_corner_topLeftRadius="@dimen/_25sdp"
pb_corner_topRightRadius Apply top right corner in rounded shape and other as it is
Ex: app:pb_corner_topRightRadius="@dimen/_25sdp"
pb_corner_bottomLeftRadius Apply bottom left corner in rounded shape and other as it is
Ex: app:pb_corner_bottomLeftRadius="@dimen/_25sdp"
pb_corner_bottomRightRadius Apply bottom right corner in rounded shape and other as it is
Ex: app:pb_corner_bottomRightRadius="@dimen/_25sdp"
pb_state_success_backgroundColor Set background color of your process state success define
Ex: app:pb_state_success_backgroundColor="@color/colorPrimary"
pb_state_success_drawable Set drawable image/icon of your process state success define
Ex: app:pb_state_success_drawable="@drawable/ic_drop"
pb_state_success_drawableTint Set drawable tint color of your process state success drawable
Ex: app:pb_state_success_drawableTint="@color/colorPrimary"
pb_state_failure_backgroundColor Set background color of your process state failure define
Ex: app:pb_state_failure_backgroundColor="@color/colorPrimary"
pb_state_failure_drawable Set drawable image/icon of your process state failure define
Ex: app:pb_state_failure_drawable="@drawable/ic_drop"
pb_state_failure_drawableTint Set drawable tint color of your process state failure drawable
Ex: app:pb_state_failure_drawableTint="@color/colorPrimary"
pb_state_with_stroke Visible stroke with state success or failure
Ex: app:pb_state_with_stroke="false"
pb_state_revert_delay Used for revert animation after delay time when after state define
Ex: app:pb_state_revert_delay="2000"
android:drawablePadding Apply padding in drawable
Ex: android:drawablePadding="@dimen/_10sdp"
pb_image_drawable Create image/icon button
Ex: app:pb_image_drawable="@drawable/ic_drop"
pb_image_drawableTint Apply tint color of image/icon
Ex: app:pb_image_drawableTint="@color/colorPrimary"
pb_anim_duration Set circle progress bar animation duration
Ex: app:pb_anim_duration="1000"
pb_anim_corner_radius Set corner rounded radius when progress bar visible
Ex: app:pb_anim_corner_radius="@dimen/_25sdp"
pb_anim_alpha_morphing Set background alpha when progress animation start
Ex: app:pb_anim_alpha_morphing="true"
pb_progress_style Set progress bar type like circle, dots or custom
Ex: app:pb_progress_style="custom"
pb_progress_drawable If you have used custom progress then set animation drawable to display progress
Ex: app:pb_progress_drawable="@drawable/animated_cloud"
pb_progress_inner_drawable When progress display at that time inside display drawable
Ex: app:pb_progress_inner_drawable="@drawable/ic_drop"
pb_progress_inner_drawableTint Set inner drawable tint color
Ex: app:pb_progress_inner_drawableTint="@color/colorPrimary"
pb_progress_width set circle progress ring width
Ex: app:pb_progress_width="@dimen/_2sdp"
pb_progress_padding Set padding from progress
Ex: app:pb_progress_padding="@dimen/_5sdp"
pb_progress_color Set circle progress color
Ex: app:pb_progress_color="@color/colorPrimary"
pb_progress_dots_count When process type dots then set number of dots display
Ex: app:pb_progress_dots_count="2"
pb_stroke_width Set stroke width
Ex: app:pb_stroke_width="@dimen/_5sdp"
pb_stroke_color Set stroke line color
Ex: app:pb_stroke_color="@color/colorPrimary"
pb_stroke_dash_width Set Stroke with dash width
Ex: app:pb_stroke_dash_width="@dimen/_5sdp"
pb_stroke_dash_gap Set stroke dash in between gap
Ex: app:pb_stroke_dash_gap="@dimen/_5sdp"
  • Then, instantiate the button
   //Create variable and bind your xml component on that object.
   val buttonLogin = findViewById<RoundButton>(R.id.fab_login)

   //For start animation and display progress bar 
   buttonLogin.startAnimation()

   //For revert animation and stop to display progress bar
   buttonLogin.revertAnimation()

   //For stop animation
   buttonLogin.stopAnimation()

Feature Roadmap

  • Progress Button Shadow.
  • Runtime Bonus.

Screen-Shot

⚠️ **GitHub.com Fallback** ⚠️