Saturday 19 March 2016

Android Material Navigation Drawer Fragment via Activities and FAB, Snackbar using Android studio

Android Material Navigation Drawer Fragment via Activities and FAB, Snackbar 
Using Android Studio 


Note: We have two methods to create Nested scrolling collapsing Activity

Method 1:

1. Create a android studio project 
  •         Open new project
  •         Fill the details 
  •         Next activity screen "Navigation Drawer Activity"



And Click finish

It takes some time to finish loading...

Now You Create the Navigation Drawer Material Design successfully.


Method 2:

If you need to include nested scrolling into your project steps are below:

1. Create a New Xml file(Right click the layout folder on Android studio).

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:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent"
    android:fitsSystemWindows="true" 
   tools:openDrawer="start">

    <include        layout="@layout/app_bar_main"
        android:layout_width="match_parent"   
     android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView 
       android:id="@+id/nav_view" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent"  
      android:layout_gravity="start"   
     android:fitsSystemWindows="true" 
       app:headerLayout="@layout/nav_header_main" 
       app:menu="@menu/activity_main_drawer" />

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




2. Create a New Xml file(Right click the layout folder on Android studio).
app_bar_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" tools:context="com.example.mmmllc.myapplication.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_dialog_email" /> </android.support.design.widget.CoordinatorLayout>


3. Create a New Xml file(Right click the layout folder on Android studio).
nav_header_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="@dimen/nav_header_height" android:background="@drawable/side_nav_bar" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:theme="@style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical" android:gravity="bottom"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="@dimen/nav_header_vertical_spacing" android:src="@android:drawable/sym_def_app_icon" android:id="@+id/imageView" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="@dimen/nav_header_vertical_spacing" android:text="Android Studio" android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="android.studio@android.com" android:id="@+id/textView" /> </LinearLayout>

4. Create a Menu Xml file(Right click the Menu folder on Android studio).
activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkableBehavior="single"> <item android:id="@+id/nav_camera" android:icon="@drawable/ic_menu_camera" android:title="Import" /> <item android:id="@+id/nav_gallery" android:icon="@drawable/ic_menu_gallery" android:title="Gallery" /> <item android:id="@+id/nav_slideshow" android:icon="@drawable/ic_menu_slideshow" android:title="Slideshow" /> <item android:id="@+id/nav_manage" android:icon="@drawable/ic_menu_manage" android:title="Tools" /> </group> <item android:title="Communicate"> <menu> <item android:id="@+id/nav_share" android:icon="@drawable/ic_menu_share" android:title="Share" /> <item android:id="@+id/nav_send" android:icon="@drawable/ic_menu_send" android:title="Send" /> </menu> </item> </menu>

5. Copy this to Manifest.Xml file.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mmmllc.myapplication" > <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" android:label="@string/app_name" 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>
6. Replace your Dependencies on "build.gradle".

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar']) 
 testCompile 'junit:junit:4.12'
 compile 'com.android.support:appcompat-v7:23.2.0'
 compile 'com.android.support:design:23.2.0' 
 Add inside into dependencies {  .........   }

if your gradle version is 23.2.0.. may be its changed by your project.. replace version number to <your version number>

Click And Run Application.
Now You Create the Navigation Drawer Material Design successfully.
Finally Create Nested Scrolling With Collapsing and FAB , Snackbar...
For Download this project:




No comments:

Post a Comment