Articles → Android → Progress Bar In Android
Progress Bar In Android
What Is Progress Bar?
Example
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"><Button android:id="@+id/button3" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:onClick="ClickEvent"
android:text="Show Progress Bar" /><ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyle"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /><TextView android:background="#00000000" android:id="@+id/progressBarText" android:visibility="gone"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignLeft="@id/progressBar" android:layout_alignTop="@id/progressBar"
android:layout_alignRight="@id/progressBar" android:layout_alignBottom="@id/progressBar"
android:text="Please wait"/></LinearLayout>
public void ClickEvent(View view) {
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
final TextView textView = (TextView) findViewById(R.id.progressBarText);
progressBar.setVisibility(View.VISIBLE);
textView.setVisibility(View.VISIBLE);
progressBar.postDelayed(new Runnable() {
@Override
public void run() {
progressBar.setVisibility(View.GONE);
textView.setVisibility(View.GONE);
}
}, 2000);
}
Output
Click to Enlarge
Click to Enlarge
Click to Enlarge