HomeActivity
public class HomeActivity extends AppCompatActivity {
private AppBarConfiguration mAppBarConfiguration;
public static Toolbar toolbar;
public static BottomNavigationView bottomNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow,R.id.cartFragment,R.id.wishFragment,R.id.dashboardFragment)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
bottomNavigationView = findViewById(R.id.bottomNavigationView);
NavigationUI.setupWithNavController(bottomNavigationView, navController);
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
}
Фрагмент корзины в нижней навигации
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_cart, container, false);
HomeActivity main = (HomeActivity) getActivity();
//You can access all public variable and methods of MainActivity.
//simply call
main.setSupportActionBar(toolbar);
main.getSupportActionBar().setDisplayHomeAsUpEnabled(false);
toolbar.setNavigationIcon(R.drawable.back_arrow);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getActivity().onBackPressed();
bottomNavigationView.setVisibility(View.VISIBLE);
}
});
bottomNavigationView.setVisibility(View.INVISIBLE);
return view;
}
}
- В фрагменте Cat первая нижняя навигация невидима
- при обратном нажатии из фрагмента корзины на в этот раз используйте видимую нижнюю навигацию. из-за того, что без видимой нижней навигации, обратное нажатие в MainActivity не отображалось. *** Вернувшись из фрагмента карты, нажмите приложение навигационного ящика cru sh