Is it possible to add an action-bar to a fragment instead of an activity.
What I am trying to create is a master-detail application with left side dedicated to the master fragment and the right side to the detail fragment. I want to add a dedicated actionbar for each of those fragment.
Does actionbarsherlock/appcompat support this feature or I would need to create a custom actionbar? / Is there a library which allows you place actionbar like thing within a linear-layout?
ActionBar is a feature of Activity. You can only control it state from fragment, but not to create. So you should implement it yourself.
Is there a library which allows you place actionbar like thing within
a linear-layout?
I don't know, but you can use <include layout="#layout/custom_action_bar"> for ActionBar placing.
Related
I want to implement a toolbar for navigation which appears at the bottom of almost all activities in my app. It will have a fixed amout of elements (four).
Screenshot:
(certain activities will still have their own toolbar at the top):
In order to make it somewhat reusable, I've created a separate layout file for the toolbar which allows me to include it on multiple activities with:
<include android:id="#+id/toolbar_main" layout="#layout/toolbar_main" />
Every item of the toolbar leads to another activity, which means it acts as a navigation throughout the whole application.
However, as I want to use it on multiple activities, I'm not sure on what would be the correct place for the Java-Code behind the onClick-Events of the menu items. I've seen approaches using a base-class which can be extended by all activities using this navigation toolbar. I've also thought about not using a toolbar at all and creating a fragment for the navigation. I haven't used fragments yet, however, they seem to have their own code-behind class in addition to their design .xml, which would be suitable for the click-Events. Any suggestions? I might add, that I want to center and stretch the navigation bar later on, which seems to be not so easy using a Toolbar with associated menu.
Make A Base activity, which will be extending by all your other activities. Write all your logic related to that toolbar on Base Activity. Thats all.
You could use the TabLayout with ViewPager. Place them in main Activity, and use Fragment for every root screen.
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'm looking through the ActionBarSherlock samples demo, and I see that the List Navigation and the Tab Navigation both make use of the ActionBar's setNavigationMode method. This tells me that you can only have one or the other. If I want the user to have list navigation to move around between activities but I want some activities to have tabs, is there a different way to add tabs than via navigation mode? Is it against ActionBar design guidelines to use both? I don't look at tabs and consider this to be a navigation feature, so I find it odd that you get one or the other.
This tells me that you can only have one or the other
Correct. Bear in mind that with action bar tabs, Android will convert you to list navigation, on its own, in certain configurations, whether you like it or not.
If I want the user to have list navigation to move around between activities but I want some activities to have tabs, is there a different way to add tabs than via navigation mode?
You can use a ViewPager with PagerTabStrip or the tab flavor of ViewPagerIndicator.
Or, you can go retro and use TabHost and TabWidget.
Is it against ActionBar design guidelines to use both?
The design guidelines refer to them as separate options for "View Controls". More importantly, given the automatic conversion of tab navigation to list navigation, it would be seriously confusing for the action bar to have two Spinners' worth of navigation choices.
Is it possible to use ActionBar without activity? I want to use it in the StatusBar view, instead of view highlighted with purple color.
This screen shot, based on an image from the Android ui pages, labels the different components, just to make sure we're talking about the same thing.
You can't add an ActionBar outside of an Activity. You need an Activity to get an ActionBar reference. ActionBar references are retrieved via the Activity API, by calling the getActionBar() method inside the Activity.
So you can't use an ActionBar to replace the StatusBar. You can change the StatusBar's color, and possibly layout, but only on a rooted phone. See this forum discussion for some perspective on the issue.
AFAIK, there is no API for changing the Notification Drawer's layout and functionality. There are no API methods that allows us to place an ActionBar inside the drawer outside of the notifications e.g. at the top of the drawer like in your screenshot.
You can create custom layouts for notifications(the messages inside the drawer). The Android Developer pages have an example on how to do it (see "Creating a Custom Notification Layout" at the bottom of the page). Again, you can't use an ActionBar but you can add Views to a Notification layout.
Use notifications. You will see something in the status bar and no Activity will be involved.
There's GOT to be a way to change the ActionBar from a class declared within an Activity:
(1) create method in activity to .setTitle
(2) pass activity context to Controller class (MVC) declared in Activity
(3) have Controller class call activity method to modify actionBar
...what do you think?
You should make a custom rom to change that view.
That Purple View is not part of your application but a part of Android.
If you do not want an Activity, why not make it transparent.
How do I create a transparent Activity on Android?
I'm building an application that requires Tabs, which are now deprecated. The dev guide says to use Fragments to replace the tabs instead. However, my application needs to have fragments within each tab, which means fragments inside fragments, which isn't allowed. Does anyone know of a possible work around for this?
While the action bar support for tabs is designed to make it easy for the contents of a tab to be a fragment, that is not strictly required. You could use ViewFlipper, repeated calls to setContentView(), or something to arrange to change other stuff when the action bar tab is selected.
Prior to the native action bar (Android 1.x/2.x), either stick with classic tabs, or use something like Action Bar Sherlock to get an action bar and tabs.
I fake tabs by having a "tabs" fragment across the top that contains multiple toggle buttons. Below that I have a merge view containing a separate fragment for each tab.
I respond to taps on a toggle button by toggling the other buttons "off", showing the fragment for that "tab", and hiding the others.
its little late , but yes you can :) here's an example
but for fragment inside fragment inside tab isn't an android native way, you have to start a new fragmentActivity if you want to show detail of fragment. you can but is not an android way !