0% found this document useful (0 votes)
54 views4 pages

MAIN Activity: Drawer

This document contains code for an Android app that implements a navigation drawer layout. It includes Java code for the main activity class that sets up the drawer, XML layout files for the activity_main, nav_header and drawer_menu. It also includes styles, manifest and string resources files to configure the app name and drawer toggle text. The app allows navigation between different sections like About Us, Faculty etc using the drawer layout.

Uploaded by

Abhi
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)
54 views4 pages

MAIN Activity: Drawer

This document contains code for an Android app that implements a navigation drawer layout. It includes Java code for the main activity class that sets up the drawer, XML layout files for the activity_main, nav_header and drawer_menu. It also includes styles, manifest and string resources files to configure the app name and drawer toggle text. The app allows navigation between different sections like About Us, Faculty etc using the drawer layout.

Uploaded by

Abhi
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/ 4

MAIN Activity

package com.example.admin.students_corner;

import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {


private DrawerLayout drawer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer=findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer,
toolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
}

activity main.xml

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


<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
android:fitsSystemWindows="true"
tools:context="MainActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#5D4037"
android:elevation="4in"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/Base.ThemeOverlay.AppCompat.Dark" />

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>

</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu"/>

</android.support.v4.widget.DrawerLayout>

Navheader.xml

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"

android:layout_width="match_parent"
android:background="@drawable/aa"
android:layout_height="160dp"
android:paddingTop="45dp">

<ImageView
android:layout_width="65dp"
android:layout_height="69dp"></ImageView>

<TextView
android:layout_width="121dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:layout_marginVertical="15dp"
android:text="SJC||BCA"
android:textColor="@color/white"
android:textStyle="italic" />

</LinearLayout>

Styles.xml
<resources>

<!-- Base application theme. -->


<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/white</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>

</resources>

Manifest

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.students_corner">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>

Drawer.xml

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


<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item android:id="@+id/nav_aboutus"
android:icon="@drawable/ic_aboutus"
android:title="About Us"/>
<item android:id="@+id/nav_faculty"
android:icon="@drawable/ic_faculty"
android:title="Faculty Members"/>
<item android:id="@+id/nav_galary"
android:icon="@drawable/ic_galary"
android:title="Gallery"/>
<item android:id="@+id/nav_achievements"
android:icon="@drawable/ic_achievements"
android:title="Achievements"/>
<item android:id="@+id/nav_notice"
android:icon="@drawable/ic_notice"
android:title="Notice"/>
<item android:id="@+id/nav_syllabus"
android:icon="@drawable/ic_syllabus"
android:title="Syllabus"/>
</group>
</menu>

String.xml

<resources>
<string name="app_name">Students_Corner</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
</resources>

You might also like