Hello , Guys Today we are going to know about
progressBar in this article.A
progressbar is a method in which we can show the
download progress in a horizontal and vertical form.
Create new Project in Android Studio
Choose "File", "New", select "New Project" and then click "Next". In the New Android Application window, enter your chosen Application, Project, and Package names and then choose "Next" and last finish. After creating the project, you will see two files, first activity_main and second MainActivity.java, then you have to paste the code given below activity_main and MainActivity.java.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".ProActivity">
<Button
android:id="@+id/hori"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Horizontal" />
<Button
android:id="@+id/circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CIRCLE PROG"
android:layout_marginTop="10dp"
android:layout_below="@+id/hori"/>
</RelativeLayout>
Here we are using two buttons in this layout, on which we will show horizontal and vertical progressbar.
MainActivity.java
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private Button hori,cir;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hori=findViewById(R.id.hori);
cir=findViewById(R.id.circle);
cir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog cir = new ProgressDialog(MainActivity.this);
cir.setProgressStyle(ProgressDialog.STYLE_SPINNER); //style
cir.setMessage("Circle ProgressBar !!");
cir.setIndeterminate(true);
cir.setCancelable(true);
cir.show();
}
}); //horizonal button
hori.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog hori = new ProgressDialog(ProActivity.this);
hori.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //style
hori.setMessage("Horizonal ProgressBar !!");
hori.setIndeterminate(true);
hori.setCancelable(true);
hori.show();
}
});
}
}
First we will set setOnClickListener on the cir variable and in onClick we will create an object cir of type ProgressDialog and pass context in it and set progressStyle on it and in it we will pass ProgressDialog.STYLE_SPINNER so that it will set circle type progress style. .And we will also make horizontal progressBar like circleBar.Below are some screenshots of how this app will workI hope this article is very useful for you.Thanks you ...
0 Comments
Please do not enter any spam link in the comment box
Emoji