具有BottomSheet的片段

时间:2018-09-28 06:03:33

标签: kotlin fragment

class BottomNavigationDrawerFragment: BottomSheetDialogFragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

        return inflater.inflate(R.layout.fragment_bottomsheet, container,false)
    }


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

        navigation_view.setNavigationItemSelectedListener { menuItem ->
            // Bottom Navigation Drawer menu item clicks
            when (menuItem.itemId) {

                R.id.nav1 ->{

                    val textFragment = fragment2()
                    // Get the support fragment manager instance
                    val manager = supportFragmentManager
                    // Begin the fragment transition using support fragment manager
                    val transaction = manager.beginTransaction()
                    // Replace the fragment on container
                    transaction.replace(R.id.frame_lay,textFragment)
                    transaction.addToBackStack(null)
                    // Finishing the transition
                    transaction.commit()
                }

                R.id.nav2 ->Toast.makeText(context, "Clicked two", Toast.LENGTH_LONG).show()

                R.id.nav3 ->Toast.makeText(context, "Clicked three", Toast.LENGTH_LONG).show()

            }

            true
        }

    }
}

我正在制作一个带有导航图标的bottomappbar,并在主活动的bottomapp栏上方创建一个片段。单击导航图标后,将创建一个包含导航视图的BottomSheetDialogFragment()对象。但是在导航视图中单击项目后,我想要仅在主要活动中更改片段,然后关闭bottomsheet。因此,在单击item1之后,我想要更改片段,但是为什么它告诉未解析的类型:supportFragmentManager?为什么我不能访问它?

0 个答案:

没有答案