コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (getIntent().hasExtra("user")) {
      mCurrentUser = getIntent().getExtras().getParcelable("user");
    }
    if (mCurrentUser == null) {
      mCurrentUser = new User("name", "level");
    }

    // set custom toolbar
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    if (mToolbar != null) {
      setSupportActionBar(mToolbar);
    }

    mNavigationDrawerFragment =
        (NavigationDrawerFragment)
            getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();

    // the drawer.
    mNavigationDrawerFragment.setUp(
        R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    // the pager
    mArticlePagerAdapter = new UserMetricsPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mArticlePagerAdapter);
    mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    mSlidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.white));
    mSlidingTabLayout.setViewPager(mViewPager);
    mViewPager.setOffscreenPageLimit(3);
  }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: khoax123/SSBSB
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setTitle("Epic Music");
    // Generate the ActionBar on top of the Activity
    // Note to Self Remove the Navigation bar until find a better way to Navigate multiple decisions
    toolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);
    // ViewPager to allow User to swipe to go to next section
    mPager = (ViewPager) findViewById(R.id.MainViewPager);
    FragmentManager fragmentManager = getSupportFragmentManager();

    mPager.setAdapter(new MyPagerAdapter(fragmentManager));

    mTabs = (SlidingTabLayout) findViewById(R.id.slidingTab);
    mTabs.setDistributeEvenly(true);
    mTabs.setBackgroundColor(getResources().getColor(R.color.primaryColor));
    mTabs.setSelectedIndicatorColors(getResources().getColor(R.color.accentColor));

    mTabs.setViewPager(mPager);

    mTabs.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            // Change Title When for selected Page

            switch (position) {
              case 0:
                {
                  setTitle("Epic Music");
                  break;
                }
              case 1:
                {
                  setTitle("Major League Gaming");
                  break;
                }
              case 2:
                {
                  setTitle("Phoenix Wright");

                  break;
                }
              case 3:
                {
                  setTitle("Dota sounds");
                  break;
                }
              case 4:
                {
                  setTitle("Random");

                  break;
                }
              case 5:
                {
                  setTitle("Random 2");

                  break;
                }
            }
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
  }