How to manage app bar when using fragments? - android

I'm using one activity as a container and multiple fragments. Some of the fragments need to display app bar, some don't while others require to show a special app bar (e.g. an app bar that shrinks when swiping up). So where should I put the app bar (or action bar), in the activity or in the fragments?
By the way, if I put the app bar inside the fragments, how should I manage the app bars properly when fragments come in or move out?

if every fragment should have a different app bar, you probably want to use a Toolbar.
Toolbar is a standalone ActionBar that you can put anywhere, in any view group. The Toolbar API is roughly the same as the ActionBar one, so you should not have any major issue migrating to Toolbar.
For your app, you should have Toolbar in every fragment, when needed and every fragment control it's own Toolbar.

Related

How to create custom status bar in Android KIOSK app

We are creating a KIOSK app on API 22. We want to have custom status bar. And with two finger swipe from the top, options menu is opened where we can edit sound, wifi etc. just like regular swipe from top on android phones.
One option would be to edit Android source code, but we are wondering if there is something we can do on application level since we need to have some strings and buttons from app in that status bar, besides WiFi signal and battery.
What we have done is we added a fragment on top of the screen which acts as a status bar, and below it is a fragment container for other fragments.
Problem here is we need to have a transparent background of the fragments in fragment container, so when user opens multiple fragments, whole fragment stack is visible in the background.
Only way we could achieve this is by using fullscreen dialog fragments, but then we had to make multiple instances of our "status bar" which overlap and only looks like one view to the user:
This leads to maintaining multiple views instead of just one. Also the problem is since we are using Navigation library, when Fragment 1 changes in the background it also pops all dialog fragments, which throws the user to screen he was not on.
One thing we tried is to set dialog fragments window to be (size of screen - status bar) but then we could not click on status bar, since it is behind our dialog fragment.
We are considering of using activities instead of fragments, since then we can have transparent background and we don't need to use dialog fragments, but to have activates everywhere instead of fragments doesn't sound like a good idea.
Are there some other options?

Different action bar for each fragment in Android - best approach?

I am building an Android project with lots of fragments that each have different action bars.
The recommended approach I've seen is to use a main layout that includes the toolbar, and then each fragment interacts with the action bar of the main layout.
To me, it seems to make more sense to just include a different toolbar separately in each fragment layout, but this goes against the approach that I see recommended everywhere. In fact, I find it quite messy to change the action bar attributes each time the fragment is started (the fragments are kept in memory). Are there any downsides to including a toolbar in each fragment individually?
In a project I'm working on I have just one main action bar for every fragment, and every time the user switches to another fragment I change the properties of it basing on the fragment id, to me this is the cleanest and most simple solution.

Android Airbnb like Tabs

I am trying to figure out how airbnb has implemented its Tab Bar, it either seems they have hidden their actionbar and everything has been shifted onto a tab bar but then the right most user icon opens the navigation drawer which should be ideally on actionbar, Or everything is on action bar itself but then how can those 3 tabs/icons on left be implemented on actionbar. (Kindly refer attached image)
Can somebody put some light on how this can be implemented. How to go about it? Also are those 3 icons fragments or separate activities?
Here, is a library which makes your life simpler to implement TabBarView for actionbar tabs.
https://github.com/Mirkoddd/TabBarView
This should give you insight about how to use it for your app.

How can I allow horizontal tab navigation (swipe views) with action bar navigation tabs?

How can I allow horizontal tab navigation (swipe views) if I'm using action bar navigation tabs?
Is there anything special I have to do to get this to work with ActionBarSherlock?
The code-generated stuff for a "Tabs+Swipe" activity (from BlankActivity in the new activity wizard in Eclipse) has code for this. Basically, your tabs tie into a ViewPager, calling setCurrentItem() to change the page, rather than running their own FragmentTransaction or otherwise affecting the UI. The ViewPager handles the horizontal swiping, and you populate those pages using some form of PagerAdapter (one is code generated for you). See this very related question and answer for more.
Is there anything special I have to do to get this to work with ActionBarSherlock?
Other than standard stuff for using ActionBarSherlock, nothing out of the ordinary should be required. ViewPager is in the Android Support package, which ActionBarSherlock also needs, so you will have that already in your project.
Note, though, that action bar tabs only sometimes show up as tabs. In some screen sizes and orientations, they are automatically converted into a drop-down list (per "list navigation" with the action bar instead of "tab navigation"). If you want to use tabs all of the time, rather than using action bar tabs with ViewPager, use PagerTabStrip (from the Android Support package) or a suitable indicator from ViewPagerIndicator instead.

Fragments Within Fragment Tabs

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 !

Categories

Resources