1

I have a BottomNavigationView which hides when the view is getting scrolled to the bottom and returns when it's scrolled to the top.

My issue is when the BottomNavigationView is hidden and I change the fragment I am unable to show the BottomNavigationView in the screen any help is appreciable.

Below is my code of DashboardActivity.kt

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:fitsSystemWindows="true"
        app:elevation="2dp">

    <include layout="@layout/toolbar"/>

</android.support.design.widget.AppBarLayout>

<FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:layout_gravity="bottom"
        app:labelVisibilityMode="selected"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
        app:itemIconTint="@android:color/white"
        app:itemTextColor="@android:color/white"
        android:background="@color/colorAccent"
        app:itemBackground="@color/colorAccent"
        app:menu="@menu/navigation"/>

Any help is appreciable

Thanks in advance

Edit #1

DashboardActivity.kt

    class DashboardActivity : BaseActivity(), EditProfileFragment.RefreshView, AddPatientFragment.NavigateView {

    override fun navigateView() {
        toDashboard()
    }

    override fun refreshView() {

        val f: Fragment? = supportFragmentManager.findFragmentById(R.id.frame_container)
        if (f != null && f is ProfileFragment) {
            f.refreshView()
            supportActionBar?.title = PROFILE

        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_dashboard)

        initializeToolBar()

        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)

        toDashboard()
    }

    /**
     * Initialization of ToolBar
     */
    private fun initializeToolBar() {

        val toolbar: Toolbar = findViewById(R.id.toolbar)
        setSupportActionBar(toolbar)

        if (supportActionBar != null) {
            supportActionBar!!.setDisplayShowHomeEnabled(true)
            supportActionBar!!.setDisplayHomeAsUpEnabled(true)
        }
    }

    private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
        when (item.itemId) {
            R.id.navigation_home -> {
                toDashboard()
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_medicine -> {
                toMedicines()
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_add_patient -> {
                toAddPatient()
                return@OnNavigationItemSelectedListener true
            }

            R.id.navigation_profile -> {
                toProfile()
                return@OnNavigationItemSelectedListener true
            }
        }
        false
    }

    private fun toProfile() {
        toggleToolBar(false)
//        navigation.selectedItemId = R.id.navigation_profile
        navigation.labelVisibilityMode = View.VISIBLE
        replaceFragment(ProfileFragment::class.java, PROFILE, false, null, R.id.frame_container)
    }

    private fun toAddPatient() {
        toggleToolBar(false)
//        navigation.selectedItemId = R.id.navigation_add_patient
        navigation.labelVisibilityMode = View.VISIBLE
        replaceFragment(AddPatientFragment::class.java, ADD_PATIENT, false, null, R.id.frame_container)
    }

    private fun toMedicines() {
        toggleToolBar(false)
//        navigation.selectedItemId = R.id.navigation_medicine
        navigation.labelVisibilityMode = View.VISIBLE
        replaceFragment(MedicineFragment::class.java, MEDICINE, false, null, R.id.frame_container)
    }

    private fun toDashboard() {
        toggleToolBar(false)
        navigation.labelVisibilityMode = View.VISIBLE
//        navigation.selectedItemId = R.id.navigation_home
        replaceFragment(HomeFragment::class.java, HOME, false, null, R.id.frame_container)
    }

    private fun toggleToolBar(value: Boolean) {
        supportActionBar?.setDisplayHomeAsUpEnabled(value)
        supportActionBar?.setDisplayShowHomeEnabled(value)
    }
}
Rakshit Nawani
  • 2,604
  • 14
  • 27

1 Answers1

-2

Update to latest Support Library Version 28.0.0-alpha1 and just add one attribute to BottomNavigationView.

<BottomNavigationView
 ....
 ....
 app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"/>

Note :- see here Hide/Show bottomNavigationView on Scroll

Imran khan
  • 123
  • 1
  • 12
  • I hope you get my question right. The behavior part is already there, the issue is how to automatically visible my BottomNavigationView when a fragment is changed – Rakshit Nawani Feb 21 '19 at 06:03
  • 1
    He is already using : `app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"` Check XML – Pratik Butani Feb 21 '19 at 06:05
  • bottomNavigation.setBehaviorTranslationEnabled(false); bottomNavigation.setTranslucentNavigationEnabled(false); use this , i have using in my code to hide permantely – Imran khan Feb 21 '19 at 10:24