示例#1
0
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.nav_tv:
        toolbar.setTitle("电视节目");

        TVFragment tvFragment = TVFragment.newInstance("", "");
        fragmentTrans(tvFragment);

        break;
      case R.id.nav_basket:
        toolbar.setTitle("NBA赛事");

        BasketFragment basketFragment = new BasketFragment();
        fragmentTrans(basketFragment);

        break;
      case R.id.nav_foot:
        toolbar.setTitle("足球联赛");

        FootFragment footFragment = FootFragment.newInstance("", "");
        fragmentTrans(footFragment);

        break;
      case R.id.nav_movie:
        toolbar.setTitle("近期影视");

        MovieFragment movieFragment = MovieFragment.newInstance("", "");
        fragmentTrans(movieFragment);

        break;
      case R.id.nav_theme:
        DialogUtils.showThemeDialog(this);

        break;
      case R.id.nav_settings:
        showCityDialog();

        break;
    }
    drawer.closeDrawer(GravityCompat.START);
    return true;
  }
示例#2
0
  private void initView() {
    toolbar.setTitle("电视节目");
    // 为什么底下的不加这个方法就能设置成功?
    setSupportActionBar(toolbar);

    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    navigationView.addHeaderView(LayoutInflater.from(this).inflate(R.layout.nav_header_main, null));

    TVFragment tvFragment = TVFragment.newInstance("", "");
    fragmentTrans(tvFragment);
  }