Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
29 views5 pages

PR 4

The document outlines a practical exercise to develop Android applications that display 'Hello World' and student information including name and marks. It includes XML layout files and Java code for two separate activities, demonstrating the use of layouts and controls. The provided code ensures proper handling of window insets for a rich user interface experience.

Uploaded by

softmicro588
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)
29 views5 pages

PR 4

The document outlines a practical exercise to develop Android applications that display 'Hello World' and student information including name and marks. It includes XML layout files and Java code for two separate activities, demonstrating the use of layouts and controls. The provided code ensures proper handling of window insets for a rich user interface experience.

Uploaded by

softmicro588
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/ 5

Practical No.

4
Practical Title: Develop a program to display Hello World on screen.
Course Level Learning Outcome : CO3
Develop rich user interface by using Layouts and Controls.

1. Write a program to display


HelloWorld. Program code:
 Activity_main.xml File
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

 MainActivity.java File
package com.example.pr4Ex1;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -
>{
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
}
Output:
2. Write a program to display student name and
marks. Program code:
 Activity_main.xml File
<?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"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TextView
android:id="@+id/titleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Information"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<TextView
android:id="@+id/nameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@id/titleText"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="20dp"/>

<EditText
android:id="@+id/nameInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:textSize="16sp"
android:inputType="text"
app:layout_constraintStart_toEndOf="@id/nameLabel"
app:layout_constraintTop_toTopOf="@id/nameLabel"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="8dp"/>
<TextView
android:id="@+id/ageLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Marks:"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@id/nameLabel"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"/>

<EditText
android:id="@+id/ageInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Enter Marks"
android:textSize="16sp"
android:inputType="number"
app:layout_constraintStart_toEndOf="@id/ageLabel"
app:layout_constraintTop_toTopOf="@id/ageLabel"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="8dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

 MainActivity.java File
package com.example.pr4Ex2;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -
>{
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
}
Output:

You might also like