In my app I want to combine a tabView with a bottom navigation bar. I want to have three tabs and three options in the bottom bar, so there should be nine different activities in the end. My tabs and the bar are defined in my activity_main.xml, so for every selected option in the bottom bar the tabs remain the same. How can I open a new fragment which depends on the combination of the selected tab and selected bottom bar option?
I suffered from a same problem before and here is my solution.
You will need 1 activity and 12 fragment not 9 to achieve it.
The main activity contains the bottom navigation bar, and inflate 3 fragment let's name them LeftFragment, MiddleFragment and RightFragment, this main activity should act only as an inflator for this fragments, don't write any other code in the activity just a manager for the bottom navigation bar.
Each one of this fragments should act as a holder or a manger for the tabs fragments, agian don't write any code in LeftFragment, MiddleFragment and RightFragment just a manager for the tablayout.
And your actual layout code should be in each tab fragment.
Hope this answer your question.
Related
I currently have a bottom navigation with 3 items for my 3 activities. I have a separate button on one of the screens that opens a new activity. When this happens, I'd like to program it so none of the 3 options of the bottom navigation view are selected.
bottomNavigationView.setSelectedItemId(R.id.______)
This is the line I use to select which icon I'd like to be shown as currently clicked. If I leave this line out of my activity, the first item of the bottom navigation view is selected by default.
I think that it will be better for you to use fragments for this task.
So I have set up the default Navigation Drawer Activity in Android Studio. I also added some buttons in the default navigation activity XML. The default navigation menu buttons obviously change the fragment, but I was wondering how I could also change the fragments via the buttons that I have added along the bottom? The reason I am having trouble is that the default nagivation menu buttons are part of a navGraph, whereas my buttons are not, thanks!
[][]
All you need to do is set onClickListeners on the button.
For example:
val postButton = findViewById<Button>(R.id.post_button)
postButton.setOnClickListener {
findNavController().navigate(R.id.post_fragment)
}
I would like to make a Fragment show up just like a Fragment Drawer would, but not only to a list of intents.
(If you don't know what I mean by Fragment Drawer):
Google products such as Gmail, "Google app", Google Play... utilize them frequently.
The Fragment Drawer is a menu on one of these apps created by swiping from left to right or clicking the "Hamburger" button.
I would like to highlight the distinction between what I want and the Fragment Drawer is: I would like to be able to place TextViews, ImageViews, and Buttons inside of it as if it were a normal fragment in which I could just inflate a layout in it and I would rather it come from the right instead.
If a visual representation is needed I would be happy to try my hand at making one.
I'm trying to build a view that will have standard tabs on the bottom and action bar tabs in the upper part of the screen.
I've tried using FragmentTabHost together with TabLayout but with no success since they both call getSupportFragmentManager() so one cancels another.
I've also thought about using deprecated TabLayoutActivity but I'm using AppCompat theme so all my activities have to inherit AppCompatActivity.
Is there a way for bottom tab to start activities and upper one fragments, or at least both starting fragments that work?
You can have 2 framelayouts (bottom,middle).
On bottom framelayout you will have a fragment with buttons as tabs, when you click on each button you will send back to activity which button clicked.
On middle framelayout you can have a TabLayout fragment and if you prefer also 1 fragment for each tab in the tablayout.
One of the solutions is to use getChildFragmentManager() available in the support library to have a Fragment inside another Fragment.
The outer one with FragmentTabHost can be controlled by main fragment manager getFragmentManager() and inner one with TabLayout by child fragment manger getChildFragmentManager().
Here's an example with nested fragments.
Still looking for a viable solution with Activity and a Fragment.
I i've a layout with 4 tabs at bottom a menu bar at the top and the all content it's to display in the center of the screen, and the tabs and menu bar is visible in all screens. In some screens I want to have some buttons to open another page (different of the tabs content) but in the center of the screen as the others.
I tried to implement that with tabhost (4 tabs), one activity per tab, but then I was in random tab and i've per example a button to show me another activity i want it to show in the center of the ecran without losing the menu bar and tab bar.
So, the best way to do this is with tabHost and a activity per tab like I did and try to find a solution for this, or just implement this using fragments?
Thanks
Instead of using the activity for each tab, use fragment for each tabhost.
Please refer the below link
http://developer.android.com/training/implementing-navigation/lateral.html