I would like to make a layout that it would be something like this:
A login layout with no toolbar or title bar
A select action layout with toolbar and no tabs
Another layout with toolbar and 3 tabs
and im thinking on how to implement this, how many fragments, activities etc.
I was thinking of having 1 activity full screen and another activity with fragments, toolbar and tab and every time i want a layut with tabs to remove the tabs and in the next screen to add again the tabs.
But after thinking it out it seems like a bad idea.
Should i create a seperate activity with fragments and tabs and navigate around those 3 layouts?
What is the best approach when you want to use tabs and a toolbar but you dont want in all your layouts to have tabs?
You only need 1 Activityand 3 Fragments. In the fragments where you need a toolbar, just use Toolbar view. This is available on Support Library so you will not have problems with older Android versions.
And in the Fragment with the tabs, just use a TabLayout and a ViewPager in order to switch between tabs (each tab is a Fragment).
Related
I'm learning about tab layout because I need to use tab layout.
When i search for tab layout on Google, the one that comes up together is the view pager.
By the way, I'm not sure about the difference between tablayout and viewpager.
The tab layout has a menu at the top and screen switching is possible.
Although the view pager does not have tabs, it is possible to slide the screen just like the tab layout.
But why use the two together?
What's different?
Isn't it possible to slide in tab layout as well?
Yes, you can use TabLayout without viewPager. But without viewpager you won't be able to slide your page. You have to handle tabselect listener manually using this method then you have to click on the tab to navigate.
addOnTabSelectedListener(OnTabSelectedListener)
Likewise, you can use only Viewpager then you will be able to slide or swipe your page without any tabs.
From official doc
TabLayout
TabLayout provides a horizontal layout to display tabs.
Viewpager
Layout manager that allows the user to flip left and right through pages of data.
So Tablayout and viewpager are two different things but you can have the privilege of both tabs and slide only by combining them.
You can check here for tablaout without viewPager
TabLayout without using ViewPager
I want to add a second row of tabs to my Android application on the second fragment accessed from the ActionBar tabs.
Tab 1 shows fragment 1.
Tab 2 shows fragment 2 but I would like fragment 2 to have a second row of tabs so it will show fragment a or b.
But it seems like fragments within fragments cannot be done and an ActionBar submenu can't be switched on or off. I have also tried with a FragmentStatePagerAdapter with a TabHost and a ViewPager which displays the tabs fine but does not display the fragments. Is there any other way to do this?
If you know the new Design Support Library ....
In your second fragment you can use TabLayout introduced in design support library 22 . Which is same as Actionbar tabs.
So just add the TabLayout in your second fragment XML.
And TabLayout has a method setUpWithViewPager(). So you can easily setup your tabs.
I hope it helps you.
here is the reference http://android-developers.blogspot.in/2015/05/android-design-support-library.html
I have implemented an ActionBar with 3 tabs in an android app. I also used ViewPager to switch between different tabs. Every tab is defined in a fragment.
The last tab is called "Setting". I have two different settings. One is "Simple" setting, and the other one is "Advanced" setting. How can I implement these two different settings in the "Setting" tab. Should I make kind of sub-fragments or two new tabs inside the main tab which is "Setting" tab? Can I also for example create two buttons at the top, and switch between them? Or any better idea? Which solution is easier and more efficient. I'm a newbie in Android.
I want to make something like this:
Hope this help
Take SettingFragment as Host fragment
Place both buttons on top and ViewPager below buttons
Take SimpleFragment and AdvanceFragment as items in ViewPager
I am trying to make an app to do the following function:
I need to have an ActionBar with 3 tabs such that one of the tabs has to implement a ViewPager and the other 2 tabs has to have separate layouts.Although I know how to create an ActionBar with Tabs with fragments, I am not sure how to(or if it is even possible) to implement a ViewPager inside one of the tabs.Thanks a lot for your help.
Edit:Nvm I found the solution.You have to use nested fragments.For more information refer to
How to add a Fragment inside a ViewPager using Nested Fragment (Android 4.2)
I'm currently developing an application that has a tab bar, and 3
different views: the first is a master-detail, the second one a
gallery, the third is a simple webview.
I was using the TabActivity, but since Android 3.0, this class is
deprecated and Android reference
suggests to use Fragments.
I switched then to an ActionBar, with Tabs and Action
Items. Inseide the first tab item I have a layout with 2 fragments (my
master-detail view). When I switch through tabs I want that my layout
change as I described above, so I thought to hide the left fragment
(the master listview) and work only in the detail fragment.. but with
this solution I have only one main activity with a lot of fragments
attached to it, and for each fragment displayed I need to modify the
Action Item shown and handle different actions in
OnOptionItemSelected.
Is this a good way to implement this kind of
application or should I consider different solutions?
You should have a single fragment container where the fragments are replaced depending on the tab selected.
One activity and multiple fragments is the right approach.