A progress bar is a graphical control element used to show the process of the operation, such as downloading, file transfer, or installation.
Create new application with any name from file menu option.
File → New Project → Application name → select API → Add Blank Activity → Activity Name → finish.
In activity_main.xml layout file design your application.
Add following Controls:-
Import Package and write following coding in MainActivity.java class file.
import android.widget.ProgressBar; import android.widget.Button; import android.widget.Toast; public class MainActivity extends ActionBarActivity { Button b1; ProgressBar pr; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.bt); pr=(ProgressBar)findViewById(R.id.progressBar); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pr.setProgress(0); new Thread(new Hello()).start(); } }); } class Hello implements Runnable { public void run() { for(int i=0;i<100;i=i+2) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } pr.setProgress(i); if(i==100) { Toast.makeText(MainActivity.this,"Progress Completed",Toast.LENGTH_LONG).show(); } } } }
Now run your application.