如果单击底部导航项,如何转换到活动而不是片段?
setContentView(R.layout.activity_main);
fm.beginTransaction().add(R.id.main_container,fragment3).hide(fragment3).commit();
fm.beginTransaction().add(R.id.main_container,fragment2).hide(fragment2).commit();
fm.beginTransaction().add(R.id.main_container,fragment1).commit(); //this is fragment
//this is implementing fragment
final BottomNavigationView bottomNavigationView = findViewById(R.id.nav_bawah);
bottomNavigationView.setSelectedItemId(R.id.navigation_dashboard);
bottomNavigationView.setOnNavigationItemSelectedListener(new
BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected( MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_dashboard:
fm.beginTransaction().hide(active).show(fragment1).commit();
active=fragment1;
break;
case R.id.navigation_challange:
fm.beginTransaction().hide(active).show(fragment2).commit();
active=fragment2;
break;
case R.id.navigation_chat:
fm.beginTransaction().hide(active).show(fragment3).commit();
active = fragment3;
break;
}
return true;
}
});
1条答案
按热度按时间3okqufwl1#
使用
Intent
开始新的活动。