android Studio在新弹出的activity使用底部导航栏(注意不是主Activity),在点击按钮切换到新activity时,退回到桌面,代码如下
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = FragmentnewActivity.inflate(getLayoutInflater());
setContentView(binding.getRoot());
BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_Fragment1, R.id.nav_Fragment2,R.id.nav_Fragment3)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_newview_main);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(binding.navView, navController);
}
个人感觉是binding的赋值和setContenView这里出了问题,但是不知道为什么