Floating action button will not disappear when going to another fragment

后端 未结 2 1019
生来不讨喜
生来不讨喜 2020-12-11 06:04

I built a project based on Scrolling Activity, and faced a strange issue. Consider the following scenario:

I click on fab button to go

2条回答
  •  無奈伤痛
    2020-12-11 07:08

    I had the same problem. I called the .hide() method on the FragmentTransaction and it worked for me.

    fab.setOnClickListener {
            val fragmentManager = fragmentManager
            val fragmentTransaction = fragmentManager?.beginTransaction()
            val fragment = YourFragment()
            fragmentTransaction?.add(R.id.fragment_container, fragment)
            fragmentTransaction?.addToBackStack(null)
            fragmentTransaction?.hide(this)
            fragmentTransaction?.commit()
        }
    

提交回复
热议问题