You could use a FragmentPagerAdapter
.
As described in the documentation (and an example from Google):
Implementation of PagerAdapter that represents each page as a Fragment
that is persistently kept in the fragment manager as long as the user
can return to the page.
This version of the pager is best for use when there are a handful of
typically more static fragments to be paged through, such as a set of
tabs. The fragment of each page the user visits will be kept in
memory, though its view hierarchy may be destroyed when not visible.
This can result in using a significant amount of memory since fragment
instances can hold on to an arbitrary amount of state. For larger sets
of pages, consider FragmentStatePagerAdapter.
Beware that depending on how many tabs your bottom bar contains, your activity could be taking a lot of memory ;)
A very complete guide from codepath could also help you a lot:
- Define Fragments
- Setup FragmentPagerAdapter
- Apply the Adapter
- Selecting or Getting the Page
- Setup OnPageChangeListener
All of these topics are explained with an example there.
About the BottomBar you have a really good example here on StackOverflow
Hope it helps! =)