Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Progress indicators on Button in Android

I am using Material Design Button in Android project. I want to have the create a Progress Indicator on button when it's pressed. It seems that the Material Design doesn't have the support yet for it.

Does anyone have suggestion how can I achieve the same in Material Design Button.

Thanks

like image 769
Ankit Avatar asked May 04 '20 05:05

Ankit


People also ask

How do I see progress on android?

In android there is a class called ProgressDialog that allows you to create progress bar. In order to do this, you need to instantiate an object of this class. Its syntax is. ProgressDialog progress = new ProgressDialog(this);

What is the use of Progress Indicator?

On Android, the “swipe to refresh” gesture displays a circular progress indicator to indicate that the UI is being refreshed. Swipe to refresh manually refreshes screen content with a user action or gesture.

What is progress bar view in android?

Android ProgressBar is a graphical view indicator that shows some progress. Android progress bar displays a bar representing the completing of the task. Progress bar in android is useful since it gives the user an idea of time to finish its task.


1 Answers

I don't think there any material component is available according to your need, but making a custom layout for the same is very easy, you can use constraint layout and place views accordingly. For example, you can give constraints to the progressbar so that it will be in the middle of your button. Try the following and check if it serves your purpose.

 <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

      <com.google.android.material.button.MaterialButton
            android:id="@+id/button_accept"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/dimen_24"
            android:layout_marginEnd="@dimen/dimen_24"
            android:backgroundTint="@color/colorGreen2"
            android:elevation="8dp"
            android:padding="@dimen/dimen_4"
            android:src="@drawable/ic_check_white"
            android:text="Accept"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ProgressBar
            android:id="@+id/progress_bar_accept"
            android:layout_width="@dimen/dimen_32"
            android:layout_height="@dimen/dimen_32"
            android:elevation="8dp"
            android:indeterminate="true"
            android:indeterminateTint="@color/colorWhite"
            android:indeterminateTintMode="src_in"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="@+id/button_accept"
            app:layout_constraintEnd_toEndOf="@+id/button_accept"
            app:layout_constraintStart_toStartOf="@+id/button_accept"
            app:layout_constraintTop_toTopOf="@+id/button_accept"/>

 </androidx.constraintlayout.widget.ConstraintLayout>

And now handle visibility of the progressbar by maintaining some logic like using flags to keep the state of it.

If you need to know about constraint layout, you can check it here: https://developer.android.com/reference/android/support/constraint/ConstraintLayout

Hope this helps.

like image 190
Parag Pawar Avatar answered Sep 22 '22 21:09

Parag Pawar