Adding navigation drawer to AppCompatActivity - android

I need to add a navigation drawer to my app. The activities extend AppCompatActivity. I want the navigation drawer to be used in some of the activities. The navigation drawer should look something like the one if the play store (i.e. a circled ImageView and some text + a listView). Can I edit the code available when creating a new navigation drawer activity in Android studio?
I tried the following code Here and extended it in my activity but it didn't work.

Sometimes using the navigation drawer template activity is a complete mess. Try this tutorial. Slidenerd is a really good source for the new material design stuff. :)

Related

Adding a navigation drawer to an existing project

I'm a beginner in Android. I have a project with multiple activities and I need to add a navigation drawer to this project instead of a normal menu. I added a new navigation drawer activity, but it doesn't show in my previous activities.
Should I add something to my existing activities?
All the tutorials I have watch use fragment while I use AppCompatActivity.
So I don't know how can I add it to my project.
Can you help me, please?
to do that, you have to use fragments instead of activities. fragments are easier to work with navigation drawers than activities. 1st you have to create a main activity for navigation drawer. Change your other activities to fragments. Then you can have navigation drawer in all the fragments. Refer below video it has everything you want. if there is any problem ask. https://www.youtube.com/watch?v=-SUvA1fXaKw

How to replace default hamburger icon with custom drawable (Used latest NavigationView, design support library, tool bar))

I have followed exact steps in the following tutorial for making navigation drawer using design support library. But i want to replace the default hamburger icon (using drawerToggle.syncState()). How can i do it?
https://github.com/codepath/android_guides/wiki/Fragment-Navigation-Drawer
Also I want to make Navigation drawer switch activities instead of fragments. For this, i have made a BaseActivity following above tutorial and extended all other activities from this BaseActivity. I am able to get the result but when a new activity is launched unable to preserve the highlighting of selected item in navigation drawer. Please suggest any solutions?

NavigationDrawer on right managed by fragment or not?

I use this library:
https://github.com/mikepenz/MaterialDrawer
I would like to have a right NavigationDrawer with a ListView (or a lot of items) inside and I get items from DB inside the Fragment and when user click on items on the NavigationDrawer I get data from another DB and show it on Fragment.
and I have a questions:
is possible to create a right Drawer inside a Fragment? or is better to create a new right Drawer in MainActivity and change the navigation item inside the Fragment?
Just use brand new Navigation View from recenlty released Android Design Support Library by Google.
Here are links for you:
official documentation, always a good read: https://developer.android.com/reference/android/support/design/widget/NavigationView.html
nicely written blog post about Navigation View: http://antonioleiva.com/navigation-view/
and last but not least, sample app using new Android Design Library: https://github.com/antoniolg/MaterializeYourApp
To have Navigation View on the right, just set android:layout_gravity to end.
As from design point of view, you should always use left sided Navigation Drawer, it is possible to make it right sided, but its recommended to leave it at the left side.
Another thing is that you do not need to use 3rd party navigation drawer libraries.Since there is a Design library by google, which supports the material design navigation view.
Here is a link for the library:
https://developer.android.com/tools/support-library/features.html
And here is another useful link:
https://guides.codepath.com/android/Design-Support-Library
Here is the link for the Navigation Drawer: https://guides.codepath.com/android/Fragment-Navigation-Drawer
As for your question the appropriate way is to create the drawer always in the main activity onCreate() method.

How to make the Navigation Drawer or bottom selection bar always accessible in an android project?

I am developing an Android project with Android Studio.
I would like to have the menu is always accessible in every view like Google Play Store (the Sidebar) and App Store (the Bottom selection bar).
I am thinking to do it in two ways:
Make my app have only one activity with Navigation Drawer, all the other views are above this activity using fragments.
Recreate the sidebar or bottom selection bar every time I switch to another activity.
Both of these two ways are very complex and cost a lot. Do you have some better ways?
PS: If not, could you suggest me some links about how to implement these two methods?
Thanks a lot.
you can create a MasterActivity that extend Activity and contain your sidebar. other Activity can extend from your MasterActivity by this way you can access your sidebar on each activity.
I think you should use the default navigation drawer and default action bar.
If you are using the Android Studio then
right click on your package and go to New/Activity/Navigation Drawer Activity.
That will create navigation drawer fragment and activity automatically.
But If you are using Eclipse then these links will be useful for you.Navigation Drawer
Action Bar
you can use include tag in other layout activity and call Navigation Drawer:
<include
android:id="#+id/nDrawer"
layout="#layout/your_NavigationDrawerLayoutName"/>

Creating a Navigation Drawer

In developer.android training there is an explnation on how to create Navigation Drawer http://developer.android.com/training/implementing-navigation/nav-drawer.html.
there is a sample app in this tuturial --> http://developer.android.com/shareables/training/NavigationDrawer.zip .
in eclipse you can also create Navigation Drawer (file->new->android application project....->Navigation Drawer activity).
in eclipse Navigation Drawer activity there is a NavigationDrawerFragment class , but in the sample app they use ListView
my question is why the sample app and eclipse Navigation Drawer activity are so diffrent (Although they have the same functionality)?
what is the use of NavigationDrawerFragment class? why to use Fragement ( instead of ListView like in the sample app)?
I never work with NavigationDrawerFragment. I think its hard or etc. If you want real Navigation Drawer go to this link=
http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
Here you have and updated Nav Drawer implementation sample according to Material Design. From Google IO 2015 it's recommended to use the Android Support Design library that will make your life easy.

Categories

Resources