导航到另一个片段后如何隐藏BottomSheetDialogFragment

时间:2021-04-05 15:13:44

标签: android kotlin navigation fragment bottom-sheet

我有一个在 XML 中包含 ImgaeView(s) 的片段,我正在从这些图像导航到另一个片段,但问题是底页保持打开状态,当我导航到另一个片段时如何使其折叠?

>

这是底片的图片

enter image description here

在这里我导航到另一个片段,但底部仍然出现在屏幕上

enter image description here

这是片段内部的代码

class MoreFragment : BottomSheetDialogFragment() {


override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
): View? {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_more, container, false)


}


override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)



    home_button.setOnClickListener{
        val homeFragment = HomeFragment()
        activity?.supportFragmentManager?.beginTransaction()
            ?.replace(R.id.nav_host_fragment, homeFragment, "findThisFragment")
            ?.addToBackStack(null)
            ?.commit()
        
    }

所以我的问题是:

导航到另一个片段后如何使其折叠?

1 个答案:

答案 0 :(得分:1)

在导航到另一个片段之前在 Onclick 侦听器中调用dismiss() 函数