Create a frame layout with text and a progress bar:
<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ProgressBar android:id="@+id/progress_bar" android:progressDrawable="@drawable/progress_bar_states" android:layout_width="match_parent" android:layout_height="match_parent" android:indeterminate="false" style="?android:attr/progressBarStyleHorizontal" /> <TextView android:id="@+id/text_view_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Enter" android:textColor="@android:color/white" android:padding="6dp" android:textSize="16sp" android:textStyle="bold" android:gravity="center"/> </FrameLayout>
You need to create a progressDrawable file.
The res / drawable / progress_bar_states.xml file declares the colors of different states:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <gradient android:startColor="#777777" android:centerColor="#333333" android:centerY="0.75" android:endColor="#222222" android:angle="270" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <gradient android:startColor="#234" android:centerColor="#234" android:centerY="0.75" android:endColor="#a24" android:angle="270" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <gradient android:startColor="#999999" android:centerColor="#777777" android:centerY="0.75" android:endColor="#555555" android:angle="270" /> </shape> </clip> </item> </layer-list>
Then create the logic for your / progressbar button:
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar); final ObjectAnimator objectAnimator = ObjectAnimator.ofInt(progressBar, "progress", progressBar.getProgress(), 100).setDuration(2000); objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int progress = (int) valueAnimator.getAnimatedValue(); progressBar.setProgress(progress); } }); TextView btn = (TextView) findViewById(R.id.text_view_button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { objectAnimator.start(); } });
Basically, after clicking on the Textview ObjectAnimator is going to increase the ProgressBar by 2 seconds to complete.
If you want to speed up the progress of this method:
private void completeFast(final ProgressBar progressBar) { final ObjectAnimator objectAnimator = ObjectAnimator.ofInt(progressBar, "progress", progressBar.getProgress(), progressBar.getMax()); objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int progress = (int) valueAnimator.getAnimatedValue(); progressBar.setProgress(progress); } }); }
He will complete the progress in 0.3 s.
Perhaps you want to change the colors of res / drawable / progress_bar_states.xml. But this is pretty much it =]
Result: 
source share