Create A ProgressBar App In Android Application Using Android Studio

Introduction

This blog explains how to develop a ProgressBar app in an Android Application, using Android Studio.

Requirements

  • Android Studio 2.1.3

Step 1

Now, open Android Studio, where you can choose the File and subsequently New. Afterwards, choose New Project.

android

Step 2

Here, you can create your application name and choose where your project is stored on the location and click Next button.

android

Now, we select Target Android Devices.

android

Step 3

Here, we can add the activity -- more activity is available  -- and click Next button.

android

Now, we can write the activity name and click Finish button.

android

Step 4

Now, open your project and you will go to activity_main.xml and afterwards, you will build the design. You should choose toolbox and if you want some options (ProgressBar(small),ProgressBar(large), button), the drag and drop method is there to help.

android

Now, we can see Graphical User Interface design.

android

Step 5

Here, you need to build on the design and write .XML code.

activity_main.xml code.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="xyz.rvconstructions.www.progresbarapp.MainActivity">  
  3.     <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start" android:id="@+id/button" android:padding="10dp" android:background="#ee00ff" android:textColor="#fff" android:layout_centerVertical="true" android:layout_centerHorizontal="true" />  
  4.     <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/progressBar" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" />  
  5. </RelativeLayout>  
Step 6

Now, you will go to MainActivity.java page and build the Java code.

First of all, you will declare a file, which is an extension file.

android

Now, we can see the MainActivity.java code.
  1. package xyz.rvconstructions.www.progresbarapp;  
  2. import android.support.v7.app.AppCompatActivity;  
  3. import android.os.Bundle;  
  4. import android.view.Menu;  
  5. import android.view.MenuItem;  
  6. import android.view.View;  
  7. import android.graphics.Color;  
  8. import android.widget.ProgressBar;  
  9. import android.widget.Button;  
  10.   
  11. public class MainActivity extends AppCompatActivity {  
  12.   
  13.     @Override  
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.activity_main);  
  17.   
  18.         final ProgressBar firstProgressBar = (ProgressBar) findViewById(R.id.progressBar);  
  19.         Button startButton = (Button) findViewById(R.id.button);  
  20.         startButton.setOnClickListener(new View.OnClickListener() {  
  21.             @Override  
  22.             public void onClick(View v) {  
  23.   
  24.                 firstProgressBar.setVisibility(View.VISIBLE);  
  25.             }  
  26.         });  
  27.     }  
  28. }  
Step 7

Here, you will go to run it and select Run-> Run app option.

android

Here, you will choose Emulator or the devices and it is Nokia Nokia _X.

android

Step 8

Here, you can see the output.

android

You will see that ProgressBar(Normal) output Window.

android

Now, you will choose the ProgressBar (Horizontal) and then you can see that horizontal xml.code

  1. <ProgressBar android:layout_width=
    "wrap_content" android:layout_height="wrap_content" android:id="@+id/progressBar" android:background="#fff700" android:layout_alignParentTop="true" android:max="100" android:progress="50" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:padding="20dp" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" />  
Now, you will run and afterwards, you can see the output given below.

android
Ebook Download
View all
Learn
View all