Skip to content
/ Tabbar Public

A Tab bar controller to manage navigation through fragments

License

Notifications You must be signed in to change notification settings

Pafgz/Tabbar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Tab bar

Platform: Android 8+ Language: Kotlin codebeat badge License

A tab bar controller to manage navigation using fragments.

How to start

Link the view with the controller

In the activity

class MyActivity : Activity(), TabBarController.Delegate {  
    val mTabBarController: TabBarController()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mTabBarView.listener = tabBarController
    }
}
Exemple of initialization
private fun initTabBarController() {
        mHomeFragment = HomeFragment()

        mOtherFragment = OtherFragment()

        mTabBarController = TabBarController(
                rootFragments(),
                supportFragmentManager,
                R.id.fragmentContainer)

        mTabBarController?.delegate = this

        mTabBarView.listener = mTabBarController

        tabBarControllerDidShowFragment(homeFragment)
}

private fun rootFragments(): List<Fragment> {
        return listOf(
                mHomeFragment,
                mOtherFragment)
    }

In the view

class TabBarView(context: Context) : LinearLayout(context) {

    var listener: TabBarViewListener? = null

How to use it

To switch tab

enum class TabBarState(val index: Int) {
    HOME(0),
    PROFILE(1)
}

//In the activity/fragment
tabBarController.switchTab(tabState.index)

To switch fragment

tabBarController.pushFragment(fragment)

To manage the back button

override fun onBackPressed() {
        if (tabBarController != null && !tabBarController!!.back()) {
            super.onBackPressed()
        }
}

About

A Tab bar controller to manage navigation through fragments

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages