布局
布局和fragment的布局是一样的。这里就不解释了
fragment的类
class StudyFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_study,container,false)
}
}
这个本质上和java差不多
如何在activity中启动
val fragmentManager = supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
val study = StudyFragment()
// 判断不同的fragment
fragmentTransaction.add(R.id.appFragment, study)
fragmentTransaction.commit()