0% found this document useful (0 votes)
13 views22 pages

Aman Andriod File

The document is a lab file for the Android Programming and Web Applications course at Amity University, detailing various experiments conducted by a student named Aman Singh. It includes a list of experiments ranging from creating a 'Hello World' application to exploring different layouts such as Constraint, Linear, Relative, and Grid Layouts. Each experiment outlines steps and code snippets for implementation in Android Studio.

Uploaded by

wff5pxnrck
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views22 pages

Aman Andriod File

The document is a lab file for the Android Programming and Web Applications course at Amity University, detailing various experiments conducted by a student named Aman Singh. It includes a list of experiments ranging from creating a 'Hello World' application to exploring different layouts such as Constraint, Linear, Relative, and Grid Layouts. Each experiment outlines steps and code snippets for implementation in Android Studio.

Uploaded by

wff5pxnrck
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Amity Institute of Information Technology

Amity University, Uttar Pradesh, Noida


Session:2022-2025(Even Semester)

[CSIT249]
Android Programming and Web Applications
for mobile devices
LAB FILE

Submitted to: Dr. Sakshi Gupta Submitted


by: Aman Singh
Enrollment no: - A10046622008
Program: BCA 4th semester

Done By:- Aman Singh


Index
List of Experiments
Sno. Name of the Experiment Signature

1. Print Hello world on the screen

2. Change background of the screen and


handling text view properties (Text size,
text style)

3. Exploring different layouts available in


Android.

4. Create a profile activity in Android

5. Linking two activities using Intent.

6. Create a login activity and validate it.

Done By:- Aman Singh


Experiment 1: Run the hello World program.
Step 1: Open Android Studio and click on “New Project”.
Step 2: It will show the activity templates on the screen. Select “Empty Activity”
and click on “Next”.

Step3: Type the name of your application. By default, it is “My Application”.


Choose the language either Java or Kotlin. Here I have chosen Java. Then select
the minimum SDK. Here I have chosen API 26. Then click on “Finish”.

Step 4: A screen will open will the activity_main.xml file and MainActivity.java
file. The text view is set to “Hello World” by default. Run this application on an
AVD.

Done By:- Aman Singh


Step 5: For running the application on AVD, click on “AVD Manager” next to play
button. Click on the button for “+ Create Virtual Devices” and choose a device.
Then click on “Next”.

Step 6: Then select a system image. Here I have chosen Oreo i.e. Android 8.0.
Then click on “Next”.

Done By:- Aman Singh


Step 7: Then choose the various other properties like orientation and click on
“Finish”.

Step 8: It will take some time to install the application on AVD. Once it gets
installed it will open with the main activity.

Done By:- Aman Singh


Experiment 2: Modify various properties like:
1. Text size, Font family
2. Status bar name and color
3. Update background
Step 1: To update the name of the application on status bar go to
app>res>values>strings.xml and change the name as per your requirement.
Here I have changed the name from My Application to Hello Pooh.

Step 2: To modify the colors of status bar go to app>res>values>styles.xml and


change the colors as per your requirement.

Done By:- Aman Singh


Step 3: Copy Paste the required background pictures and image view pictures in
app>res>drawable folder. Then change the xml codes in
app>res>layout>activity_main.xml for sizes of text in text view and add the
code for background of layout.
Script:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/floral"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/pooh" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="118dp"
android:layout_marginTop="32dp"
android:text="Hello Pooh"
android:textSize="36sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
</androidx.constraintlayout.widget.ConstraintLayout>

Done By:- Aman Singh


Screen:

Step 4: Run the application on AVD.

Done By:- Aman Singh


Experiment 3: Show various types of layout.
1. Constraint Layout
Step 1: Choose the buttons and align them as per your requirement and
set their margins.
Script:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/floral"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="49dp"
android:layout_marginTop="114dp"
android:backgroundTint="#CDDC39"
android:text="Previous"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="147dp"
android:layout_marginEnd="49dp"
android:backgroundTint="#FFEB3B"
android:text="Next"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button3" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="139dp"
android:layout_marginTop="281dp"
android:layout_marginEnd="139dp"
android:backgroundTint="#009688"
android:text="Scroll to Top"
android:textColor="#F8F4F4"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Step 2: Run the application on AVD.

Done By:- Aman Singh


Observation: The views can be placed anywhere if their margins are set in
Constraint Layout.

2. Linear Layout
Step 1: Change the layout name from Constraint to Linear Layout in the
activity.xml file, also choose the orientation i.e. horizontal or vertical. And
add the views required.
Script:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/floral"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CDDC39"
android:text="Previous"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFEB3B"
android:text="Next"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button3" />

<Button

Done By:- Aman Singh


android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#009688"
android:text="Scroll to Top"
android:textColor="#F8F4F4"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>

Step 2: Run the application on AVD.

Observation: In Linear Layout the views get aligned one after the other or
in a linear pattern as the name suggests. The orientation could be either
horizontal or vertical.

Note: Here the gravity is set to “center”. By default, it is left and it can be
changed as per your need.

3. Relative Layout
Step 1: Change layout name from Constraint to Relative Layout in
activity_main.xml.
Script:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/floral"
android:gravity="center"
android:orientation="horizontal"
tools:context=".MainActivity">

<Button

Done By:- Aman Singh


android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CDDC39"
android:text="Previous"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#009688"
android:text="Scroll to Top"
android:textColor="#F8F4F4"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFEB3B"
android:text="Next"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button3" />

</RelativeLayout>

Step 2: Run the application on AVD.

Observation: The views in relative layout overlap each other.

4. Grid Layout
Step 1: Change layout name from Constraint to Grid Layout in
activity_main.xml.
Script:

Done By:- Aman Singh


<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/floral"
android:orientation="horizontal"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#CDDC39"
android:text="Previous"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#009688"
android:text="Scroll to Top"
android:textColor="#F8F4F4"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFEB3B"
android:text="Next"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button3" />

</GridLayout>

Step 2: Run the application on AVD.

Done By:- Aman Singh


Observation: In Grid Layout, the views are aligned in a grid like pattern as
shown in the template above.

Done By:- Aman Singh


Experiment 4: Profile activity in Android
Xml File Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/deer_background_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.286" />

<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.453"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.125"
app:srcCompat="@drawable/dp" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.122"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.393" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Course "
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"

Done By:- Aman Singh


app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.126"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Batch"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.122"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.594" />

<EditText
android:id="@+id/editTextText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Enter Your Name"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.37" />

<EditText
android:id="@+id/editTextText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Enter Your Course"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/editTextText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Enter Your Batch"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"

Done By:- Aman Singh


app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.588" />

</androidx.constraintlayout.widget.ConstraintLayout>

Done By:- Aman Singh


Experiment 5: Linking two activities using Intents.
Step 1: Open Android Studio and click on “New Project”.
Step 2: It will show the activity templates on the screen. Select “Empty Activity”
and click on “Next”.

Step3: Type the name of your application. By default, it is “My Application”.


Choose the language either Java or Kotlin. Here I have chosen Java. Then select
the minimum SDK. Here I have chosen API 26. Then click on “Finish”.

Step4: Create activities:--


<activity android:name=“. FirstActivity" />
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

Done By:- Aman Singh


xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/delhi_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DelhiMap">

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.256"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.265" />
</androidx.constraintlayout.widget.ConstraintLayout>

<activity android:name=".SecondActivity" />


package com.example.connecting2ormoreactivites;

Done By:- Aman Singh


import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.widget.Button;
public class DelhiMap extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delhi_map);
Button btn;
btn= (Button)findViewById(R.id.button3);

btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

Toast.makeText(getApplicationContext(),"This is the
End",Toast.LENGTH_LONG).show();

}
});

}
}

Step5:Design Layout: --

Done By:- Aman Singh


Step6:Define Intent:--
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
Step7:Start Activity:--
Step8: Back Navigation and Handelthe Back Buttons:--

Done By:- Aman Singh


Done By:- Aman Singh

You might also like