我正在使用BottomNavigation Bar Library( roughike )
请检查附带的SnapShot如图所示,当前选择了库我要选择它。并且dnt想要在我想要时显示任何选定的项目。
请帮忙。
mBottomBar = BottomBar.attach(this,savedInstanceState); mBottomBar.useDarkTheme();
mBottomBar.setItemsFromMenu(R.menu.bottom_tab, new OnMenuTabClickListener() {
@Override
public void onMenuTabSelected(@IdRes int menuItemId) {
if (menuItemId == R.id.HomeTab) {
displayView(0);
}
if (menuItemId == R.id.ProfileTab) {
displayView(1);
}
if (menuItemId == R.id.GalleryTab) {
displayView(2);
}
if (menuItemId == R.id.FriendsTab) {
displayView(3);
}
if (menuItemId == R.id.SettingTab) {
displayView(4);
}
}
@Override
public void onMenuTabReSelected(@IdRes int menuItemId) {
if (menuItemId == R.id.HomeTab) {
displayView(0);
}
if (menuItemId == R.id.ProfileTab) {
displayView(1);
}
if (menuItemId == R.id.GalleryTab) {
displayView(2);
}
if (menuItemId == R.id.FriendsTab) {
displayView(3);
}
if (menuItemId == R.id.SettingTab) {
displayView(4);
}
}
});
public void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
fragment = new MainWall();
break;
case 1:
fragment = new Profile();
break;
case 2:
fragment = new Gallery();
break;
case 3:
fragment = new Friends();
break;
case 4:
fragment = new Settings();
break;
case 5:
fragment = new Messages();
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
// update selected item and title, then close the drawer
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Necessary to restore the BottomBar's state, otherwise we would
// lose the current tab on orientation change.
mBottomBar.onSaveInstanceState(outState);
}