What is the best way to add fragment in the Tabs android

后端 未结 4 618
南方客
南方客 2021-01-17 00:17

My application had a bottom navigation bar which has 5 tabs. So according to these tabs, I have 5 fragments When I click on the tab, the fragment changed according to that t

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-17 00:45

    you don't have to need to hide the fragment just replace the fragment like this method:

    public void setFragment(Fragment fragmentWhichYouWantToShow) {
    
            fm = getSupportFragmentManager();
            ft = fm.beginTransaction();
            ft.replace(R.id.container, fragmentWhichYouWantToShow);
            ft.commit();
    

    }

提交回复
热议问题