I have a fragment which I use as a menu bar on top of the screen to switch between activities and show which activity is currently open by highlighting its icon. It is hardcoded through XML in 4 of my activies. These activities are represented by icons and each icon has an onclicklistener which loads the appropriate activity when clicked. My question is, when I have a transition to switch between activities, is it possible to keep the menu bar in place and only switch the content of the activity like in Vine or YikYak with the sliding model. If this requires recoding all 4 activities I won't do it as it's only for eye-candy however I would like to know how difficult and time consuming this would be.
For the short answer, by replacing the Activity, you replace the entire UI, so no, it isn't possible.
The long answer is this:
Vine and YikYak don't replace the entire Activity, only the Fragments. So if you had a layout structured like this:
Activity
|-- Menu Bar
|-- Content
then YikYak and Vine only replace the Content Fragment, not the Activity. This is essentially what Google recommends with the DrawerFragment. In order to do this you would have to rewrite your entire app to make use of Fragment changes rather than Activity changes. I would recommend doing this despite the extra work, as its one of the main benefits to using Fragments at all.
Related
I had an app which was developed 2 years back, now I want to add navigation drawer to that app, but the problem is in that app there are 15 Activities, so do I need to apply the Navigation drawer for all 15 Activities? or is there best way to implement this.?
The navigation drawer items are common for whole app.
Can anyone suggest me the best way to implement this.
A way you can do it, since Navigation Drawers are just list fragments, is create a list fragment and recall that same fragment in all the activities that you want it in. You can do this using the XML Layout Editor to place the fragment in the layout.
Having so many activities, however, makes it a lot of work (especially if your app is designed for multiple sizes and each activity has a layout).
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 have made a nice app with a whole bunch of activities , then i needed a navigation drawer and found out that you need to have only one activity for the whole app and the individual different screens should be fragments that are inserted at runtime.
my question is :
How to convert the entire app to use fragments instead of activities ? (eg: how to preserve activity hierarchy , show a main activity when the user opens the app , different actionbar for each screen , etc...)
There is no magic converter, you need to convert manually each activity to be extended from Fragment
and add few must methods like onCreateView for the fragment instead of SetContentView of activity.
Regarding the actionbars, it sits on the Main Activity so you need to create callback events from each fragment to the main activity in order to control the action bar.
Navigation drawer has nothing related to fragments.
If you wish you can put it into activities also.
What I created was a BaseActivity with layout having navigation drawer and all other activities extend BaseActivity so that each of your activity will have drawer. Only you need to change content page for particular activity.
happy coding.
I am using a Navigation Drawer currently with the Android Example. I plan to change this to using SlidingMenu Library as it's easier and provides easy customisation methods. I will also use the SherlockActionBar. I will have about 4-5 different Activities and each will have different ActionBar actions depending certain states. For all the Activities, I want to display the same Navigation Drawer/Sliding menu. Currently, I am using Fragments as per the Android Example to switch and inflate new Layouts each time a new item is selected from the drawer. As this is done inside the MainActivity, all four xml layout's share the same .java Activity file which makes it long and messy.
Using the SlidingMenu Library and SherlockActionBar, can I avoid Fragments and singular Activity and link the same Navigation Drawer/Sliding menu to all the Activites?
Yes, you can use one SlidingMenu for all the activities. Make a separate base activity and implement slidingmenu in that Activity and extend all the activities in your project with that activity.
I want to create a app with a menu at the bottom of the screen. This menu should be visible any time the app is started.
Im working with fragments, so the menu is one fragment.
So I have only one Activity as controller which loads different fragments above the menu fragment.
Because I want to create clean code, i dont know how to solve the problem that the Activity class is too big.
In other words, i want to create different controller within the same activity. How to do that?
Is there another approach to solve this issue?
You should be using the split action bar This allows you to put the Actions and overflow menu on the bottom of the screen. I believe you can use Action Bar Sherlock for backwards compatibility to older versions of Android. See their site for detail.
Another possibility is to look into using fragments with the ViewPager . Here is a library that works with compatability as well ViewPageIndicator . Here is a blog post , like I indicated in my comment I got this working with the tabs showing at the bottom and the pages above.