Progress Dialog in Android Example
Before we show you how to create a Progress Dialog in Android, let us make sure that you understand the basics. This article will cover everything you need to know about dialog in Android, starting from a simple dialog to creating a dialog in Android from scratch.
For those who are new to this field, a dialog is basically just a small box or window that appears in front of a user’s current activity. When this happens, the focus is shifted from the underlying activity to the dialog. The basic purpose of dialogs is to notify the user about something and to perform quick tasks associated with the application. Dialogs are divided into four main types: Alert Dialog, Progress Dialog, Date Picker Dialog and Time Picker Dialog. Our point of focus in this article is Progress Dialog.
Android Progress Dialog
You must have seen an Android Progress Dialog in the UI of an Android app. It is a dialog box which, as the name suggests, shows the progress of a task. The simplest Android Progress Dialog shows a spinning wheel, also known as progress wheel. It can also have buttons and a progress bar that shows the loading status, but that requires some additional coding. A common example of an Android Progress Dialog is the dialog box you see while you are uploading or downloading a file.
If you are still unclear about what an Android Progress Dialog is, the following example of a typical dialog may help you:Open the MainActivity.java file, and add the following code in it:
This code basically is the key to run our project as it is, in simpler words, the first screen to appear when our project is launched. Without this, performing other additional activities is not possible.Open your layout file, i.e. activity_main.xml, and enter the following code in it:
This codes means that we have used the “ProgressBar” widget (to create a progress bar) and have added other features to it, such as a horizontal style, maximum value of 100, centralized text, minimum height of 50 dp, etc. We have also used the “LinearLayout” widget with a vertical orientation to arrange our contents vertically. Other than that, we have used the “TextView” widget, which will display text to the user, and the “Button” widget to create a button in the Progress Dialog that says “GO.”