Introduction
This blog explains how to develop a ProgressBar app in an Android Application, using Android Studio.
Requirements
Step 1
Now, open Android Studio, where you can choose the File and subsequently New. Afterwards, choose New Project.
Step 2
Here, you can create your application name and choose where your project is stored on the location and click Next button.
Now, we select Target Android Devices.
Step 3
Here, we can add the activity -- more activity is available -- and click Next button.
Now, we can write the activity name and click Finish button.
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.
Now, we can see Graphical User Interface design.
Step 5
Here, you need to build on the design and write .XML code.
activity_main.xml code.
- <?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: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">
- <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" />
- <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" />
- </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.
Now, we can see the MainActivity.java code.
- package xyz.rvconstructions.www.progresbarapp;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.graphics.Color;
- import android.widget.ProgressBar;
- import android.widget.Button;
-
- public class MainActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- final ProgressBar firstProgressBar = (ProgressBar) findViewById(R.id.progressBar);
- Button startButton = (Button) findViewById(R.id.button);
- startButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- firstProgressBar.setVisibility(View.VISIBLE);
- }
- });
- }
- }
Step 7
Here, you will go to run it and select Run-> Run app option.
Here, you will choose Emulator or the devices and it is Nokia Nokia _X.
Step 8
Here, you can see the output.
You will see that ProgressBar(Normal) output Window.
Now, you will choose the ProgressBar (Horizontal) and then you can see that horizontal xml.code
<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.