Android - Change fragment layout in runtime

前端 未结 2 1123
情歌与酒
情歌与酒 2021-02-04 15:22

I would like to implement a Single-Activity Multi-Fragments design in my app. I plan to have several \"screens\" (layouts of Fragment) that I\'ll switch between (possibly adding

2条回答
  •  梦谈多话
    2021-02-04 15:58

    this.loadFragment(AlarmExample.newInstance())
    this.loadFragment(XmlParsingFragment.newInstance())
    
    private fun loadFragment(fragment: Fragment) {
        supportFragmentManager.beginTransaction()
            .replace(R.id.fragmentContainer, fragment)
            .commit()
    }
    

    In this way, you can set any fragment, based upon your requirement.

提交回复
热议问题