Ejemplo n.º 1
0
  private void initView(Bundle savedInstanceState) {

    List<Fragment> fragments = new ArrayList<>(4);

    fragments.add(HomeFragment.newInstance(0));
    fragments.add(HomeFragment.newInstance(0));
    fragments.add(HomeFragment.newInstance(0));
    fragments.add(MeFragment.newInstance(0));

    mNavController =
        new FragNavController(
            savedInstanceState, getSupportFragmentManager(), R.id.container, fragments);

    mBottomBar = BottomBar.attach(this, savedInstanceState);
    mBottomBar.useOnlyStatusBarTopOffset();

    mBottomBar.setItems(R.menu.bottombar_menu);
    mBottomBar.setOnMenuTabClickListener(
        new OnMenuTabClickListener() {
          @Override
          public void onMenuTabSelected(@IdRes int menuItemId) {

            switch (menuItemId) {
              case R.id.bottomBarItemOne:
                mNavController.switchTab(INDEX_RECENTS);
                break;

              case R.id.bottomBarItemOne1:
                mNavController.switchTab(INDEX_FAVORITES);
                break;

              case R.id.bottomBarItemOne2:
                mNavController.switchTab(INDEX_NEARBY);
                break;

              case R.id.bottomBarItemOne3:
                mNavController.switchTab(INDEX_FRIENDS);
                break;
            }
          }

          @Override
          public void onMenuTabReSelected(@IdRes int menuItemId) {

            switch (menuItemId) {
              case R.id.bottomBarItemOne:
                Toast.makeText(NewMainActivity.this, "Home", Toast.LENGTH_SHORT).show();
                break;
              case R.id.bottomBarItemOne1:
                break;
              case R.id.bottomBarItemOne2:
                break;
              case R.id.bottomBarItemOne3:
                break;
            }
          }
        });
  }
Ejemplo n.º 2
0
  private void initBottomBar(Bundle savedInstanceState) {
    BottomBar mBottomBar = BottomBar.attach(this, savedInstanceState);
    mBottomBar.setItems(R.menu.main_bottom_bar);
    mBottomBar.setOnMenuTabClickListener(
        new OnMenuTabClickListener() {
          @Override
          public void onMenuTabSelected(@IdRes int menuItemId) {
            String fragmentTag = getFragmentTag(menuItemId);
            mFragment = getSupportFragmentManager().findFragmentByTag(fragmentTag);
            openScreen(fragmentTag);
          }

          @Override
          public void onMenuTabReSelected(@IdRes int menuItemId) {
            // Do nothing
          }
        });
  }
Ejemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.white_text));
    fragments = new SparseArray<>();
    colors = new SparseArray<>();

    fragments.put(R.id.bottomBarItem1, new FirstPageFragment());
    fragments.put(R.id.bottomBarItem2, new TabFragment());
    fragments.put(R.id.bottomBarItem3, new FirstPageFragment());
    fragments.put(R.id.bottomBarItem4, new FirstPageFragment());
    colors.put(R.id.bottomBarItem1, ContextCompat.getColor(this, R.color.tab_color_1));
    colors.put(R.id.bottomBarItem2, ContextCompat.getColor(this, R.color.tab_color_2));
    colors.put(R.id.bottomBarItem3, ContextCompat.getColor(this, R.color.tab_color_3));
    colors.put(R.id.bottomBarItem4, ContextCompat.getColor(this, R.color.tab_color_4));
    BottomBar mBottomBar = BottomBar.attach(this, savedInstanceState);
    mBottomBar.setItemsFromMenu(
        R.menu.button_menu,
        new OnMenuTabClickListener() {
          @Override
          public void onMenuTabSelected(int menuItemId) {
            Fragment tragetFragment = fragments.get(menuItemId);
            setFragment(tragetFragment);
            toolbar.setBackgroundColor(colors.get(menuItemId));
            setTranslucenttatus(colors.get(menuItemId));
          }

          @Override
          public void onMenuTabReSelected(int menuItemId) {}
        });

    mBottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.tab_color_1));
    mBottomBar.mapColorForTab(1, ContextCompat.getColor(this, R.color.tab_color_2));
    mBottomBar.mapColorForTab(2, ContextCompat.getColor(this, R.color.tab_color_3));
    mBottomBar.mapColorForTab(3, ContextCompat.getColor(this, R.color.tab_color_4));
  }