My Life with Android
Introduction Android Componets UserInterface Advanced UI Data Storage Advanced Concepts Others New Studio

Android Progressbar

Example
  1. Add ProgressBar in res/layout/activity_main.xml
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        
    <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:visibility="gone" />
    <Button android:id="@+id/btnShow" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show" /> <Button android:id="@+id/btnHide" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/btnShow" android:text="Hide" /> </RelativeLayout>
  2. Add code in src/your app package/MainActivity.java
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ProgressBar;
    
    public class ProgressBarEx extends Activity{
    	Button btnShow,btnHide;
    	ProgressBar progressBar1;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.progressbar_ex);
    		btnShow=(Button)findViewById(R.id.btnShow);
    		btnHide=(Button)findViewById(R.id.btnHide);
    		progressBar1=(ProgressBar)findViewById(R.id.progressBar1);
    		btnShow.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				progressBar1.setVisibility(View.VISIBLE);
    			}
    		});
    		btnHide.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				progressBar1.setVisibility(View.GONE);
    			}
    		});
    	}
    }
    
OUT PUT

Android - Layout