Screenshots :
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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"
tools:context="com.chantisandroid.exampleapp.MainActivity">
<include layout="@layout/header" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to ChantisAndroid's Android Tutorial"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:textColor="@color/black"
android:textSize="15dp"/>
</RelativeLayout>
<include layout="@layout/slidemenu" />
</android.support.v4.widget.DrawerLayout>
slidemenu.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/left_drawer"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:fillViewport="true" >
<FrameLayout
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<RelativeLayout
android:id="@+id/RLSide"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollbars="none" >
<!-- The navigation drawer -->
<RelativeLayout
android:layout_width="260dp"
android:layout_height="match_parent"
android:id="@+id/drawerPane"
android:layout_gravity="start">
<!-- Profile Box -->
<RelativeLayout
android:id="@+id/profileBox"
android:layout_width="260dp"
android:layout_height="130dp"
android:layout_marginTop="20dp">
<ImageView
android:id="@+id/avatar"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/kba_personn" />
<TextView
android:id="@+id/farmername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/avatar"
android:layout_marginTop="26dp"
android:layout_toRightOf="@+id/avatar"
android:text="ChantisAndroid"
android:textColor="@color/black"
android:textSize="20dp" />
</RelativeLayout>
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#BDBDBD"
android:layout_below="@+id/profileBox"/>
<RelativeLayout
android:id="@+id/Home"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@+id/text1"
android:layout_marginTop="10dp"
android:padding="8dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/hme"
android:orientation="vertical" >
<TextView
android:id="@+id/txt_home"
android:layout_width="match_parent"
android:layout_height="42dp"
android:gravity="left|center"
android:text="Home"
android:textStyle="bold"
android:textColor="@color/black"
android:textSize="16sp" />
</LinearLayout>
<ImageView
android:id="@+id/hme"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="1dp"
android:src="@drawable/kba_home" />
</RelativeLayout>
<TextView
android:id="@+id/text2"
android:layout_width="187dp"
android:layout_height="1dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:background="#BDBDBD"
android:layout_alignParentRight="true"
android:layout_below="@+id/Home"/>
<RelativeLayout
android:id="@+id/services"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@+id/text2"
android:padding="8dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/seting"
android:orientation="vertical" >
<TextView
android:id="@+id/txt_service"
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="Services"
android:textStyle="bold"
android:gravity="left|center"
android:textColor="@color/black"
android:textSize="16sp" />
</LinearLayout>
<ImageView
android:id="@+id/seting"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/kba_services" />
</RelativeLayout>
<TextView
android:id="@+id/text3"
android:layout_width="187dp"
android:layout_height="1dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:background="#BDBDBD"
android:layout_alignParentRight="true"
android:layout_below="@+id/services"/>
<RelativeLayout
android:id="@+id/terms"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@+id/text3"
android:padding="8dp"
android:layout_marginTop="2dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/img_terms"
android:orientation="vertical" >
<TextView
android:id="@+id/txt_terms"
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="Privacy & Terms"
android:textStyle="bold"
android:gravity="left|center"
android:textColor="@color/black"
android:textSize="16sp" />
</LinearLayout>
<ImageView
android:id="@+id/img_terms"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="1dp"
android:src="@drawable/kba_newprivacy" />
</RelativeLayout>
<TextView
android:id="@+id/text5"
android:layout_width="187dp"
android:layout_height="1dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:background="#BDBDBD"
android:layout_alignParentRight="true"
android:layout_below="@+id/terms"/>
<RelativeLayout
android:id="@+id/feedback"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@+id/text5"
android:padding="8dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/img_feedback"
android:orientation="vertical" >
<TextView
android:id="@+id/txt_feedback"
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="Feedback"
android:gravity="left|center"
android:textStyle="bold"
android:textColor="@color/black"
android:textSize="16sp" />
</LinearLayout>
<ImageView
android:id="@+id/img_feedback"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="1dp"
android:src="@drawable/kba_newfeedback" />
</RelativeLayout>
<TextView
android:id="@+id/text6"
android:layout_width="187dp"
android:layout_height="1dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:background="#BDBDBD"
android:layout_alignParentRight="true"
android:layout_below="@+id/feedback"/>
<RelativeLayout
android:id="@+id/aboutus"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@+id/text6"
android:padding="8dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/img_aboutus"
android:orientation="vertical" >
<TextView
android:id="@+id/txt_aboutus"
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="About us"
android:textStyle="bold"
android:gravity="left|center"
android:textColor="@color/black"
android:textSize="16sp" />
</LinearLayout>
<ImageView
android:id="@+id/img_aboutus"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="4dp"
android:src="@drawable/kba_aboutus" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<View
android:layout_width="0.5dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true" />
</RelativeLayout>
</RelativeLayout>
header.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/header"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/top_layout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimary"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="14dp"
android:src="@drawable/menu_icn" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView"
android:layout_centerVertical="true"
android:layout_marginLeft="40dp"
android:text="Example App"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
MainActivity.java:
package com.chantisandroid.exampleapp;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public RelativeLayout mDrawerList;
public DrawerLayout mDrawerLayout;
TextView home,service,terms,feedback,aboutus;
ImageView drawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (RelativeLayout) findViewById(R.id.left_drawer);
drawer = (ImageView)findViewById(R.id.imageView);
drawer.setOnClickListener(this);
home = (TextView) findViewById(R.id.txt_home);
home.setOnClickListener(this);
service = (TextView) findViewById(R.id.txt_service);
service.setOnClickListener(this);
terms = (TextView) findViewById(R.id.txt_terms);
terms.setOnClickListener(this);
feedback = (TextView) findViewById(R.id.txt_feedback);
feedback.setOnClickListener(this);
aboutus = (TextView) findViewById(R.id.txt_aboutus);
aboutus.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.imageView:
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.openDrawer(mDrawerList);
}
break;
case R.id.txt_home:
Toast.makeText(this,"Home",Toast.LENGTH_LONG).show();
break;
case R.id.txt_service:
Toast.makeText(this,"Services",Toast.LENGTH_LONG).show();
break;
case R.id.txt_terms:
Toast.makeText(this,"Terms & Conditions",Toast.LENGTH_LONG).show();
break;
case R.id.txt_feedback:
Toast.makeText(this,"Feedback",Toast.LENGTH_LONG).show();
break;
case R.id.txt_aboutus:
Toast.makeText(this,"About us",Toast.LENGTH_LONG).show();
break;
}
}
}
No comments:
Post a Comment