Android: how to load fragment into FrameLayout

后端 未结 3 827
孤街浪徒
孤街浪徒 2020-12-10 05:09

I\'m starting with Android and in my project I\'m using this BottomBar. Love it, works pretty well. The code of my application is almost identical on to the one he uses in t

3条回答
  •  甜味超标
    2020-12-10 05:36

    First you have a mistake in your Fragment transaction line, according with your layout should be:

    transaction.replace(R.id.contentContainer, newFragment); // not R.id.bottomBar
    

    Second, you should use supportFragmentManager instead of fragmentManager to work with support fragments, so implement the following way:

    final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.contentContainer, newFragment);
    transaction.addToBackStack(null);
    transaction.commit();
    

提交回复
热议问题