In google developer blog post . I read about new way to create navigation drawer using new dependency called
compile 'com.android.support:design:22.2.0'
but I didn’t found exact way to create navigation drawer using this new dependency.
In build.gradle , I have added dependency
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:appcompat-v7:22.0.0'
in layout file added following code (based on google blog post)
<android.support.v4.widget.DrawerLayout
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"
android:fitsSystemWindows="true">
<!-- your content layout -->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Aslo I tried to extend class using ActionBarActivity but its deprecated?
Ref:http://android-developers.blogspot.in/2015/05/android-design-support-library.html
Any help appreciated .Thank you
activity_main
app_bar_main
content_main
nav_header_main
activity_main_drawer
colors
dimens
MainActivity
dependencies
styles
styles-v21
The "java part" can look like this:
Set your activity as a listener
And than handle events the same way you handle menu interaction
Check this github project for all examples of using design library.
It's not clear exactly what your issue is (in what way did it not work?), but perhaps you missed the fact that you muse actually define the 'drawer_header' layout and the 'drawer' menu?
If that's not the problem, please explain in more detail exactly what you're having a problem with.
Hi try following steps
Add Android design support library dependency
Create a header for the navigation drawer
Create a menu for navigation drawer items
Create Navigation View with header and items
Implementing Navigation View
you can directly download source code from my blog
hello @user3739665 i am also trying to lean support library, but i don't think there is proper way(because no sample available right now). so here is my tried code, just for demonstration how to use that lib.
i change that layout to like below added main fragment, you can also add toolbar.
i have create
drawer.xml
for menu anddrawer_header.xml
for user detail just like show in blogmy activity code
}
add this in you build.gradle
drawer.xml
drawer_header.xml
EDIT
added navigation item open,close, enable items selection
Tutorial: Navigation View Design Support Library