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




Picture showing the output of progress bar in android
Click to Enlarge



Picture showing the output of progress bar in android
Click to Enlarge



Picture showing the output of progress bar in android
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, November 20, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250