Custom Progressbar and ProgressDialog
Posted By : Deepanshu Harbola | 30-Jun-2016
A progressbar or progressdialog is very important ui asset in app development. A developer use them in case of loading some data from server or from device or to show user that somthing is going on and some work is in progress.
We can use android's default progressbar or progressdialog or can make our own custom ui for them.
Here we are going to make a small app which will focuse on the custom progressdialog and progressbar.
1- Custom ProgressBar
Layout for progressbar-
family:arial,helvetica,sans-serif;"> <
Animation class-
2- Custom ProgressDialog
Layout for progressdialog-
Custom progressdialog class-
public class CustomProgressDialogOne { public void showCustomDialog(Context context) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context); final View dialogView = LayoutInflater.from(context).inflate(R.layout.custom_progress_dialog_one, null); dialogBuilder.setView(dialogView); dialogBuilder.setCancelable(true); RelativeLayout mainLayout = (RelativeLayout) dialogView.findViewById(R.id.mainLayout); mainLayout.setBackgroundResource(R.drawable.my_progress_one); AnimationDrawable frameAnimation = (AnimationDrawable)mainLayout.getBackground(); frameAnimation.start(); AlertDialog b = dialogBuilder.create(); b.show(); } }
Code to animate the progressdialog-
Activity to show the working things-
public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button btnProgressBar; private Button btnProgressDialogOne,btnProgressDialogTwo; private ProgressBar viewProgressBar; private CustomProgressDialogTwo customProgressDialogTwo; private CustomProgressDialogOne customProgressDialogOne; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initializeViews(); clickListener(); } private void initializeViews() { btnProgressBar = (Button) findViewById(R.id.btnProgressBar); btnProgressDialogOne = (Button) findViewById(R.id.btnProgressDialogOne); btnProgressDialogTwo = (Button) findViewById(R.id.btnProgressDialogTwo); viewProgressBar = (ProgressBar) findViewById(R.id.viewProgressBar); customProgressDialogTwo = new CustomProgressDialogTwo(this,R.drawable.loadingicon); customProgressDialogOne = new CustomProgressDialogOne(); } private void clickListener() { btnProgressBar.setOnClickListener(this); btnProgressDialogOne.setOnClickListener(this); btnProgressDialogTwo.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.btnProgressBar: viewProgressBar.setVisibility(View.VISIBLE); break; case R.id.btnProgressDialogOne: viewProgressBar.setVisibility(View.GONE); customProgressDialogOne.showCustomDialog(this); break; case R.id.btnProgressDialogTwo: viewProgressBar.setVisibility(View.GONE); customProgressDialogTwo.show(); break; } } }
For more Download the complete project from here
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Deepanshu Harbola
Deepanshu is an Android application developer with experience in Titanium Framework . Deepanshu likes to play basketball ,volleyball and listens to music in his free time.