Friday 21 October 2016

Internet Connection Example in Android

activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.chantisandroid.checkinternet.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Welcome to ChantisAndroid"
        android:id="@+id/textView"
        android:layout_marginTop="178dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

MainActivity.java:
package com.chantisandroid.checkinternet;

import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (MainActivity.this.checkInternetConnection()) {
            MainActivity.this.ShowMessage("Internet is Connected");

        } else {
            MainActivity.this.ShowMessage("Please Check Your Internet Connection");
        }
    }
    public  boolean  checkInternetConnection() {

        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm == null) {
            return false;
        } else {
            NetworkInfo[] info = cm.getAllNetworkInfo();
            if (info != null) {
                for (int i = 0; i < info.length; i++) {
                    if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public void ShowMessage(String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(message).setCancelable(false)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }

}


AndroidManifest.xml:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.chantisandroid.checkinternet">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Wednesday 7 September 2016

BarCode Scanner example in android

screenshots:


build.gradle(Module: app) :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.chantisandroid.barcodescanner"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'me.dm7.barcodescanner:zxing:1.8.4' //add this line here

}


activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">

    <Button
        android:id="@+id/scanner"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:text="Scanner"
        android:layout_marginTop="48dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp" />

</RelativeLayout>


MainActivity.java:

package com.chantisandroid.barcodescanner;

import android.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;

public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler, View.OnClickListener {
    private ZXingScannerView mScannerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = (Button)findViewById(R.id.scanner);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {

        mScannerView = new ZXingScannerView(this);
        setContentView(mScannerView);

        mScannerView.setResultHandler(this);
        mScannerView.startCamera();
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();
    }

    @Override
    public void handleResult(Result rawResult) {

        Log.e("handler", rawResult.getText());
        Log.e("handler", rawResult.getBarcodeFormat().toString());
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Scan Result");
        builder.setMessage(rawResult.getText());
        AlertDialog alert = builder.create();
        alert.show();
    }

}

AndroidManifest.xml:


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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.chantisandroid.barcodescanner">

    <uses-permission android:name="android.permission.CAMERA" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Saturday 20 August 2016

SnackBar Example in Android





build.gradle(Module: app) :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.chantisandroid.exampleapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'

    compile 'com.android.support:design:23.0.1' //you can add this line

}


activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    android:id="@+id/coordinatorLayout"
    tools:context=".MainActivity">

 <RelativeLayout
        android:id="@+id/relout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="simple snackbar"
        android:id="@+id/button"
        android:layout_alignParentTop="true"
        android:layout_marginTop="50dp"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2"
        android:layout_alignLeft="@+id/button2"
        android:layout_alignStart="@+id/button2" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="with action snackbar"
            android:id="@+id/button2"
            android:layout_below="@+id/button"
            android:layout_centerHorizontal="true" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="custom  snackbar"
            android:id="@+id/button3"
            android:layout_below="@+id/button2"
            android:layout_alignLeft="@+id/button2"
            android:layout_alignStart="@+id/button2"
            android:layout_alignRight="@+id/button2"
            android:layout_alignEnd="@+id/button2" />

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="16dp"
        android:src="@android:drawable/ic_dialog_dialer" />

</android.support.design.widget.CoordinatorLayout>


MainActivity.java:

package com.chantisandroid.exampleapp;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    CoordinatorLayout coordinatorLayout;
    private Button button, button2, button3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);

        FloatingActionButton floating = (FloatingActionButton) findViewById(R.id.floating);
        floating.setOnClickListener(this);


        button = (Button) findViewById(R.id.button);
        button2 = (Button) findViewById(R.id.button2);
        button3 = (Button) findViewById(R.id.button3);

        button.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.floating:
                Snackbar.make(v, "FloatingActionButton is clicked", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
                break;

            case R.id.button:
               Snackbar.make(coordinatorLayout, "https://chantisandroid.blogspot.in/",
                       Snackbar.LENGTH_LONG).show();
                break;

            case R.id.button2:
                Snackbar snackbar = Snackbar
                        .make(coordinatorLayout, "Contact deleted", Snackbar.LENGTH_LONG)
                        .setAction("UNDO", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Snackbar snackbar1 = Snackbar.make(coordinatorLayout, "Contact restored!", Snackbar.LENGTH_SHORT);
                                snackbar1.show();
                            }
                        });

                snackbar.show();

                break;

            case R.id.button3:
                Snackbar bar = Snackbar
                        .make(coordinatorLayout, "Try again!", Snackbar.LENGTH_LONG)
                        .setAction("RETRY", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                            }
                        });
                bar.setActionTextColor(Color.RED);
                View sbView = bar.getView();
                TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
                textView.setTextColor(Color.YELLOW);
                bar.show();

         }
     }
}

Floating Lables EditText example in Android





build.gradle(Module: app) :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.chantisandroid.floatinglables"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'   //you can add this line
}


activity_main.xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="60dp"
        android:layout_alignParentTop="true">


        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:hint="Full Name" />


        </android.support.design.widget.TextInputLayout>


        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:hint="Phone" />


        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Password" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_repassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_repassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Confirm Password" />
        </android.support.design.widget.TextInputLayout>

        <Button android:id="@+id/button_signup"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Sign Up"
            android:background="@color/colorPrimary"
            android:layout_marginTop="40dp"
            android:textColor="#ffffff"/>

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>


MainActivity.java:

package com.chantisandroid.floatinglables;

import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    EditText Name,phone, Email, Password,repassword;
    TextInputLayout LayoutName,LayoutPhone ,LayoutEmail, LayoutPassword ,LayoutRepassword;
    Button SignUp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LayoutName = (TextInputLayout) findViewById(R.id.layout_name);
        LayoutPhone = (TextInputLayout) findViewById(R.id.layout_phone);
        LayoutEmail = (TextInputLayout) findViewById(R.id.layout_email);
        LayoutPassword = (TextInputLayout) findViewById(R.id.layout_password);
        LayoutRepassword = (TextInputLayout) findViewById(R.id.layout_repassword);

        Name = (EditText) findViewById(R.id.editText_name);
        phone = (EditText) findViewById(R.id.editText_phone);
        Email = (EditText) findViewById(R.id.editText_email);
        Password = (EditText) findViewById(R.id.editText_password);
        repassword = (EditText) findViewById(R.id.editText_repassword);

        SignUp = (Button) findViewById(R.id.button_signup);
        SignUp.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

    }
}


Thursday 11 August 2016

Spalsh Screen Example in Android




activity_main.xml :


<?xml version="1.0" encoding="utf-8"?>
<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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to ChantisAndroid&apos;s Android Tutorials"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="90dp"
        android:textSize="16dp"
        android:textColor="#000000" />
</RelativeLayout>


activity_splash_screen.xml :


<?xml version="1.0" encoding="utf-8"?>
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.chantisandroid.exampleapp.SplashScreen"
    android:background="#ffffff">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="68dp"
        android:background="@drawable/logo" />
</RelativeLayout>


Now create anim folder under res folder
under anim folder create one xml file

animation_in_goes_here.xml :


<?xml version="1.0" encoding="utf-8"?>
<set>
     <scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="3000"
    android:fromXScale="0"
    android:fromYScale="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="1"
    android:toYScale="1" >
    </scale>

</set>


MainActivity.java


package com.chantisandroid.exampleapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}


SplashScreen.java


package com.chantisandroid.exampleapp;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashScreen extends Activity {

    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Window window = getWindow();
        window.setFormat(PixelFormat.RGBA_8888);
    }
    Thread splashTread;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);

        ImageView iv = (ImageView)findViewById(R.id.imageView);

        Animation zoomin = AnimationUtils.loadAnimation(this, R.anim.animation_in_goes_here);
        iv.setAnimation(zoomin);

        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    // Splash screen pause time
                    while (waited < 1000) {
                        sleep(400);
                        waited += 100;
                    }
                    Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(intent);
                    SplashScreen.this.finish();
                } catch (InterruptedException e) {
                    // do nothing
                } finally {
                    SplashScreen.this.finish();
                }

            }
        };
        splashTread.start();
    }
}


AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.chantisandroid.exampleapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity"></activity>
    </application>

</manifest>



Monday 8 August 2016

Navigation Drawer example in Android


Screenshots :


activity_main.xml :


<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" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ffffff"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        />

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


simple.xml :


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="20dp"
    android:paddingTop="10dp"
    android:textColor="@color/colorPrimary"
    android:textSize="25dp" >
</TextView>


MainActivity.java :


package com.chantisandroid.exampleapp;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

@SuppressLint("NewApi")
public class MainActivity extends ActionBarActivity {
    DrawerLayout drawerLayout;
    ListView drawerListView;
    String[] SOFTWARES = { "Android", "Java", "Oracle", "Microsoft","php","ios",".net" };
    ActionBarDrawerToggle actionBarDrawerToggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerListView = (ListView) findViewById(R.id.left_drawer);

        actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
                R.drawable.menu_icn, R.string.drawer_open,
                R.string.drawer_close);

        drawerLayout.setDrawerListener(actionBarDrawerToggle);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        ArrayAdapter<String> adapter = new ArrayAdapter<>(
                getApplicationContext(), R.layout.simple, SOFTWARES);

        drawerListView.setAdapter(adapter);

        drawerListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View arg1,
                                    int position, long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(),
                        adapter.getItemAtPosition(position).toString(),
                        Toast.LENGTH_LONG).show();

                drawerLayout.closeDrawers();
            }
        });
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        actionBarDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        actionBarDrawerToggle.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}



Custom Navigation Drawer using Slidemenu in Android


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&apos;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 &amp; 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;
      }
    }
}

Alarm Manager Example in Android