0% found this document useful (0 votes)
18 views8 pages

Mobile Application Assignment 3

Uploaded by

Daud Sajid
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)
18 views8 pages

Mobile Application Assignment 3

Uploaded by

Daud Sajid
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/ 8

Assignment 3

Mobile App Development


Name: Muhammad Daud Sajid

Roll No: 028

Class: BSSE 7A FA21

XML:

Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<androidx.drawerlayout.widget.DrawerLayout
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/drawerlayout"
tools:openDrawer="start"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<include layout="@layout/mian_activity_content"></include>

<com.google.android.material.navigation.NavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/drawer_items"
app:headerLayout="@layout/drawer_header"
android:layout_gravity="start"
>

</com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>
Main_activity_cotent.xml:

<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp">

<Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#009688">

<ImageButton
android:id="@+id/openDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

app:srcCompat="@android:drawable/ic_menu_sort_by_size"
android:padding="15dp"/>

</Toolbar>

<TextView
android:id="@+id/t1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn on the switch to use Navigtion Drawer"
android:layout_marginTop="50dp"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="center"/>

<Switch
android:id="@+id/switch1"
android:layout_width="172dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_gravity="center"
android:text="Switch"
android:textSize="20sp"/>
</LinearLayout>

Drawer_header.xml:

<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#871DE7BC"
android:padding="20dp"
android:gravity="center">

<ImageButton
android:id="@+id/imageButton"
android:layout_width="100dp"
android:layout_height="96dp"
app:srcCompat="@drawable/person" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group 8A"
android:textStyle="bold"
></TextView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[email protected]"
></TextView>

</LinearLayout>

JAVA:

MainActivity.java:

package com.example.mid_prep_lab;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Switch;
import android.widget.Toast;

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

public class MainActivity extends AppCompatActivity {

DrawerLayout Dl;
ImageButton openDl;
Switch s1;

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

Dl=findViewById(R.id.drawerlayout);
openDl=findViewById(R.id.openDrawer);
s1=findViewById(R.id.switch1);

openDl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(s1.isChecked()) {
Dl.open();
}
else {
Toast.makeText(MainActivity.this, "turn on the Switch first", Toast.LENGTH_SHORT).show();
}
}
});
}
}

Screenshot:

You might also like