How to Create Bottom Navigation Bar in Androidx in Sketchware
//1st ASD Block
com.google.android.material.bottomnavigation.BottomNavigationView
btm= new com.google.android.material.bottomnavigation.BottomNavigationView
(MainActivity.this);
btm.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
linear1.addView(btm);
linear1.setElevation(16);
Menu menu = btm.getMenu();
final int A = 0;
final int B = 1;
final int C = 2;
final int D = 3;
final int E = 4;
menu.add(Menu.NONE, A, Menu.NONE, "Home").setIcon(R.drawable.ic_home_grey);
menu.add(Menu.NONE, B, Menu.NONE, "Money").setIcon(R.drawable.ic_money_grey);
menu.add(Menu.NONE, C, Menu.NONE, "Favorites").setIcon(R.drawable.ic_favorites_grey);
menu.add(Menu.NONE, D, Menu.NONE, "Profile").setIcon(R.drawable.ic_person_grey);
menu.add(Menu.NONE, E, Menu.NONE, "Report").setIcon(R.drawable.ic_report_grey);
//2nd ASD Block
btm.setOnNavigationItemSelectedListener(new com.google.android.material.bottomnavigation.BottomNavigationView
.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(final MenuItem item) {
switch (item.getItemId()){
case A:
showMessage("item1");
break;
case B:
showMessage("item2");
break;
case C:
showMessage("item3");
break;
case D:
showMessage("item4");
break;
case E:
showMessage("item5");
break;
} return true; } });
Comments
Post a Comment