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
Related
I've created a base activity for navigation drawer and every other activity will extend this to display the drawer.
Doing this will re-create the drawer for each activity.
Is there any kind of workaround for this such that a common drawer is used across all the activities?
EDIT:
Source of what I've referred to do this:
Same Navigation Drawer in different Activities
I prefer using fragments instead of activities when dealing with a navigation drawer, this will both be more efficient and good looking.
A guide on how to do this can be found at:
fragment-navigation-drawer-guide
In short no, or at least: You should not do that.
Navigation drawers are usually to be used with fragments that you swap, they should not create new activities, since the drawer can not (or should not) be shared.
You should overthink your navigation, and use fragments instead where appropriate. Following the design guidelines, again, navigation drawers should be the top most navigation, and no other activities should have one either.
The answer on how to use a common drawer would hence be to use an activity with the drawer managing different fragments.
If you absolutely must, you can detach the navigation drawer view from the layout, keep the reference some place, then reuse the same view in another activity. This is really dirty and as mentioned, you should not do this.
My application contains 6 Activities. I added a Navigation Drawer to my toolbar in all of them in order to toggle between them. I understand that Navigation Drawers are better suited for Fragments and that this adds a lot more code as I'm creating this drawer in each activity but is this ok to do? The application functions fine, I'm just wondering if it's good programming practice? Thank you.
I'm working on my App about 6 Months.
I don't know if I misread it but, is it possible to create and add a Navigation Drawer when I have different Activities?
How my App works:
SplashScreen -> LogInScreen -> Activity 1(ListView) -> Activity 2 (after click on ListView item) -> ... and so on.
Is it possible to add now a Navigation Drawer? I read something that you can add a Navigation Drawer only if you don't switch between Activities is that right?
I want a Navigation that looks on every Activity different. Is it possible or it can only have one layout?
I hope my problem is clearly explained.
Kind Regards
All your other Activities should extend The MainActivity which contains the navigationView .
helphuf links : Same Navigation Drawer in different Activities , Android: Navigation-Drawer on all activities
Yes, it is possible. I suggest following option to use navigation drawer in all Activities of App.
You have a two option :
1) Use Fragment instead of Activity and put navigation drawer to First Activity.
for Example : http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
2) Create One layout for navigation-drawer and include it to all layout of your Activities using "" tag in xml Like this link : navigation drawer layout with include layout
for Example : Same Navigation Drawer in different Activities
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"/>
I got a navigation drawer on the activity of my app, but once I get the fragment parts of my app running (through a fragmentActivity) I have trouble programming a navigation process over there. I want my users to be able to navigate from one fragment to another fragment using the navigation drawer, making life easier.
Does anyone have a solution to this?
I think what you want is a ViewPagerIndicator, and to use a ViewPager with a FragmentPagerAdapter to page your Fragments.