我有一个底部导航栏与4节片段附加。在每个片段都有一些东西,通过点击,我将到其他片段,这不是节片段。我想显示底部导航栏只在节片段。那么如何隐藏底部导航栏在其他片段?
下面是我的底部导航条形码:
package com.fahim69.bazaarapp.FragmentHolder;
public class ShowFragment extends AppCompatActivity {
BottomNavigationView bottomnav;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_fragment);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
bottomnav = findViewById(R.id.nav_bar);
replacefragment(new HomeFragment());
bottomnav.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment = null;
switch (item.getItemId()) {
case R.id.nav_home:
replacefragment(new HomeFragment());
break;
case R.id.nav_category:
replacefragment(new CategoryFragment());
break;
case R.id.nav_cart:
replacefragment(new CartFragment());
break;
case R.id.nav_profile:
replacefragment(new ProfileFragment());
break;
}
return true;
}
});
}
private void replacefragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
//fragmentManager.popBackStack();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
@Override
public void onBackPressed() {
FragmentManager fm = getSupportFragmentManager();
if(fm.getBackStackEntryCount()>0)fm.popBackStack();
else{
super.onBackPressed();
}
}
}
1条答案
按热度按时间iszxjhcz1#
请看下面地代码替换片段:
我们正在加载“R.layout.activity_show_fragment”布局的“R.id.fragment_container”框架上的所有片段。在show_fragment布局中,存在一个导航栏,因此所有片段都显示为底部导航。
为了隐藏sectionfragment之外的其他片段中的底部导航,请创建一个不带bottom_navigation的新Activity,并替换该Activity的新fragment_container中的片段。