I am having quite a challenge, i was following some tutorial project but when we reached a point of adding a bottom navigation bar, I have been stuck here for weeks trying to figure out where the problem is. The activity loads successfully but i can not switch between the different tabs on the bottom navigation bar namely, Home, Add and Logout.
Here is my Code for the activity.
public class SellerHomeActivity extends AppCompatActivity {
private TextView mTextMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seller_home);
BottomNavigationView navView = findViewById(R.id.nav_view);
navView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_add:
Intent intentCategory = new Intent(SellerHomeActivity.this, SellerProductCategoryActivity.class);
startActivity(intentCategory);
return true;
case R.id.navigation_logout:
final FirebaseAuth mAuth;
mAuth = FirebaseAuth.getInstance();
mAuth.signOut();
Intent intentMain = new Intent(SellerHomeActivity.this, MainActivity.class);
intentMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intentMain);
finish();
return true;
}
return false;
}
});
// 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.navigation_home, R.id.navigation_add, R.id.navigation_logout)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
// NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); NavigationUI.setupWithNavController(navView, navController); }
}
Any help rendered will be so helpful to me, Thanks in advance