从bottomnavigation取消选择我的菜单项,只显示菜单,没有任何突出显示的项目

时间:2016-04-18 07:39:01

标签: android menu material-design navigationbar

我正在使用BottomNavigation Bar Library( roughike

请检查附带的SnapShot如图所示,当前选择了库我要选择它。并且dnt想要在我想要时显示任何选定的项目。

请帮忙。

SnapShot

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);
}

0 个答案:

没有答案