Esempio n. 1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_exam, container, false);
    ButterKnife.bind(this, v);

    ExamAdapter adapter = new ExamAdapter(getChildFragmentManager());
    examNavigationTab.setTabsFromPagerAdapter(adapter);
    examNavigationView.setAdapter(adapter);
    examNavigationTab.setTabsFromPagerAdapter(adapter);
    examNavigationTab.setupWithViewPager(examNavigationView);
    examNavigationTab.setTabMode(TabLayout.MODE_FIXED);
    examNavigationTab.setTabGravity(TabLayout.GRAVITY_FILL);
    return v;
  }
 private void setUpTabLayoutAndViewPager() {
   ContentPagerAdapter contentPagerAdapter = new ContentPagerAdapter(getSupportFragmentManager());
   mViewPager.setAdapter(contentPagerAdapter);
   mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
   mTabLayout.setTabsFromPagerAdapter(contentPagerAdapter);
   mTabLayout.setupWithViewPager(mViewPager);
 }
  private void setUpPagerAndTabs() {
    pager = (ViewPager) findViewById(R.id.pager);
    pagerAdapter =
        new StreamMediaPlayerPagerAdapter(StreamVideoActivity.this, getSupportFragmentManager());
    pager.setAdapter(pagerAdapter);
    pager.setOffscreenPageLimit(2);
    tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.setTabsFromPagerAdapter(pagerAdapter);
    tabLayout.setupWithViewPager(pager);
    tabLayout.setOnTabSelectedListener(
        new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
            pager.setCurrentItem(tab.getPosition());
          }

          @Override
          public void onTabUnselected(TabLayout.Tab tab) {
            if (tab.getPosition() == 0) {
              pagerAdapter.mFragment.hideAll();
            }
          }

          @Override
          public void onTabReselected(TabLayout.Tab tab) {}
        });
  }
Esempio n. 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mCoordinator = (CoordinatorLayout) findViewById(R.id.root_coordinator);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mToolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(mToolbar);

    navigationView = (NavigationView) findViewById(R.id.navigation_drawer);
    navigationView.setItemIconTintList(null);
    navigationView.setNavigationItemSelectedListener(this);

    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

    mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
    mAdapter = new TabPagerAdapter(this, getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.view_pager);
    mPager.setAdapter(mAdapter);
    // Notice how the Tab Layout links with the Pager Adapter
    mTabLayout.setTabsFromPagerAdapter(mAdapter);

    // Notice how The Tab Layout adn View Pager object are linked
    mTabLayout.setupWithViewPager(mPager);
    mPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
    if (getIntent() != null) {
      mPager.setCurrentItem(getIntent().getIntExtra("tab", 0));
    }
    fragmentManager = getSupportFragmentManager();
  }
Esempio n. 5
0
  private void configViews() {

    // 设置显示Toolbar
    setSupportActionBar(mToolbar);

    // 设置Drawerlayout开关指示器,即Toolbar最左边的那个icon
    ActionBarDrawerToggle mActionBarDrawerToggle =
        new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open, R.string.close);
    mActionBarDrawerToggle.syncState();
    mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);

    // 给NavigationView填充顶部区域,也可在xml中使用app:headerLayout="@layout/header_nav"来设置
    mNavigationView.inflateHeaderView(R.layout.view_nav_header);
    // 给NavigationView填充Menu菜单,也可在xml中使用app:menu="@menu/menu_nav"来设置
    mNavigationView.inflateMenu(R.menu.menu_nav);
    // 自己写的方法,设置NavigationView中menu的item被选中后要执行的操作
    onNavgationViewMenuItemSelected(mNavigationView);

    // 初始化ViewPager的适配器,并设置给它
    pageAdapter = new CardPageAdapter(getSupportFragmentManager(), mTitles);
    mViewPager.setAdapter(pageAdapter);
    // 设置ViewPager最大缓存的页面个数
    mViewPager.setOffscreenPageLimit(5);
    // 给ViewPager添加页面动态监听器(为了让Toolbar中的Title可以变化相应的Tab的标题)
    mViewPager.addOnPageChangeListener(this);

    mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    // 将TabLayout和ViewPager进行关联,让两者联动起来
    mTabLayout.setupWithViewPager(mViewPager);
    // 设置Tablayout的Tab显示ViewPager的适配器中的getPageTitle函数获取到的标题
    mTabLayout.setTabsFromPagerAdapter(pageAdapter);

    // 设置FloatingActionButton的点击事件
    mFloatingActionButton.setOnClickListener(this);
  }
Esempio n. 6
0
  private void initViewPager(View view) {
    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    mTabLayout = (TabLayout) view.findViewById(R.id.tabs);

    mViewPager.setAdapter(new NewsPagerAdapter(getActivity(), getFragmentManager()));
    mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    mTabLayout.setupWithViewPager(mViewPager);
    mTabLayout.setTabsFromPagerAdapter(mViewPager.getAdapter());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tool_list);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE);
    if (mToolType == null) {
      throw new IllegalStateException("ToolType not available as extra; use startActivity");
    }
    setTitle(mToolType.getToolNameResourceId());

    // Set up tabs
    mViewPager = (ViewPager) findViewById(R.id.viewpager);
    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    final ToolPagerAdapter toolPagerAdapter =
        new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType);
    tabLayout.setTabsFromPagerAdapter(toolPagerAdapter);
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    mViewPager.setAdapter(toolPagerAdapter);
    tabLayout.setOnTabSelectedListener(this);

    // Handle animation from previous activity
    postponeEnterTransition();
    mViewPager
        .getViewTreeObserver()
        .addOnPreDrawListener(
            new ViewTreeObserver.OnPreDrawListener() {
              @Override
              public boolean onPreDraw() {
                mViewPager.getViewTreeObserver().removeOnPreDrawListener(this);
                startPostponedEnterTransition();
                return true;
              }
            });

    setEnterSharedElementCallback(
        new SharedElementCallback() {
          @Override
          public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            if (mViewPager.getCurrentItem() != 0) {
              // Not displaying the about page, which has the hero image
              names.clear();
              sharedElements.clear();
            }
          }
        });
  }
Esempio n. 8
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_cards, container, false);

    final FloatingActionButton btn = (FloatingActionButton) rootView.findViewById(R.id.btn);
    btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getActivity(), CoordinatorLayoutActivity.class);

            Bundle bundle = new Bundle();
            // bundle.putString("name", "杭州公交卡");
            // bundle.putString("number", "1111111111111111111");
            // intent.putExtra("data", bundle);
            intent.putExtra("cardInfo", new CardInfo("杭州公交卡", "1111111111111111111"));

            // startActivity(intent);
            startActivityForResult(intent, 0);
          }
        });
    ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
    //        TextView txtCard=(TextView) rootView.findViewById(R.id.txtCard);
    //        txtCard.setText(mTitle);

    TabLayout tabs = (TabLayout) rootView.findViewById(R.id.tablayout);
    tabs.addTab(tabs.newTab().setText("Tab1"));
    tabs.addTab(tabs.newTab().setText("Tab2"));
    tabs.addTab(tabs.newTab().setText("Tab3"));
    tabs.addTab(tabs.newTab().setText("Tab4"));
    tabs.addTab(tabs.newTab().setText("Tab5"));
    tabs.addTab(tabs.newTab().setText("Tab6"));
    List<String> titles = new ArrayList<>();
    List<Fragment> fragments = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
      String title = "Tab" + (i + 1);
      tabs.addTab(tabs.newTab().setText(title));
      titles.add(title);
      Fragment fragment = CardsFragment.newInstance(title, title);
      fragments.add(fragment);
    }

    cardFragmentAdapter mAdapter =
        new cardFragmentAdapter(getActivity().getSupportFragmentManager(), titles, fragments);
    viewPager.setAdapter(mAdapter);
    tabs.setupWithViewPager(viewPager);
    tabs.setTabsFromPagerAdapter(mAdapter);

    return rootView;
  }
Esempio n. 9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // setup view pager
    MainFragmentPagerAdapter adapter =
        new MainFragmentPagerAdapter(fragmentManager, titles, titles.length);
    viewPager.setAdapter(adapter);

    // setup tabs
    tabLayout.setTabsFromPagerAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);
    for (int ii = 0; ii < tabLayout.getTabCount(); ii++) {
      tabLayout.getTabAt(ii).setCustomView(R.layout.tab_view);
    }
  }
Esempio n. 10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_matchday_detail);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new MatchdayPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    // By using this method the tabs will be populated according to viewPager's count and
    // with the name from the pagerAdapter getPageTitle()
    tabLayout.setTabsFromPagerAdapter(mSectionsPagerAdapter);
    tabLayout.setupWithViewPager(mViewPager);
    realmDBManager = new ZappRealmDBManager();

    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            createMatchday();
          }
        });

    RealmResults<Matchday> list = realmDBManager.list_all_matchdays();

    setMatchday(new Matchday());
    DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
    String date = df.format(Calendar.getInstance().getTime());
    getMatchday().setDatum(date);

    EventBus.getDefault().register(this);
  }
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void initData() {

    ArrayList<String> tabList = new ArrayList<>();
    tabList.add("Tab1");
    tabList.add("Tab2");
    tabList.add("Tab3");

    mTabLayout.setTabMode(TabLayout.MODE_FIXED);

    mTabLayout.addTab(mTabLayout.newTab().setText(tabList.get(0)));
    mTabLayout.addTab(mTabLayout.newTab().setText(tabList.get(1)));
    mTabLayout.addTab(mTabLayout.newTab().setText(tabList.get(2)));

    ArrayList<Fragment> viewList = new ArrayList<>();

    for (int i = 0; i < tabList.size(); i++) {
      Fragment f1 = new TabFragment();
      Bundle bundle = new Bundle();
      bundle.putString("content", "http://blog.csdn.net/feiduclear_up \n CSDN 废墟的树");
      f1.setArguments(bundle);
      viewList.add(f1);
    }

    TabFragmentAdapter fragmentAdapter =
        new TabFragmentAdapter(getFragmentManager(), viewList, tabList);
    viewPager.setAdapter(fragmentAdapter); // 给ViewPager设置适配器
    mTabLayout.setupWithViewPager(viewPager); // 将TabLayout和ViewPager关联起来。
    mTabLayout.setTabsFromPagerAdapter(fragmentAdapter); // 给Tabs设置适配器

    mToolbar.setLogo(R.mipmap.ic_launcher);
    mToolbar.setLogoDescription("齐鲁壹点");

    mToolbar.setNavigationIcon(R.mipmap.small_logo);
    mToolbar.setNavigationContentDescription("测试");
    mToolbar.setNavigationOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Toast.makeText(CustomCoordinatorActivity.this, "HHHHHH", Toast.LENGTH_SHORT).show();
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_header_scrolling);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // set the toolbar min height
    //        int toolbar_height = PlatformUtils.getToolbarHeight(this) * 2;
    //        CollapsingToolbarLayout.LayoutParams params = (CollapsingToolbarLayout.LayoutParams)
    // toolbar.getLayoutParams();
    //        params.height = toolbar_hight;
    //        toolbar.setLayoutParams(params);

    appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
    appBarLayout.addOnOffsetChangedListener(this);

    mTabLayout = (TabLayout) findViewById(R.id.tab_layout);

    List<String> titles = new ArrayList<>();
    titles.add(" One ");
    titles.add(" Two ");
    titles.add(" Three ");

    mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(0)));
    mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(1)));
    mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(2)));

    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mViewPager.setOffscreenPageLimit(3);

    List<Fragment> fragments = new ArrayList<>();
    mLinearRecyclerFragment = new LinearRecyclerFragment();
    fragments.add(mLinearRecyclerFragment);
    fragments.add(new NestedScrollFragment());
    mGridRecyclerFragment = new GridRecyclerFragment();
    fragments.add(mGridRecyclerFragment);

    mAdapter = new MainTabAdapter(getSupportFragmentManager(), fragments, titles);
    mViewPager.setAdapter(mAdapter);
    mTabLayout.setupWithViewPager(mViewPager);
    mTabLayout.setTabsFromPagerAdapter(mAdapter);

    mHeadViewPager = (ViewPager) findViewById(R.id.header_viewpager);
    mHeadViewAdapter = new HeadViewAdapter(this, null);
    ArrayList<String> headList = new ArrayList<String>();
    headList.add("1111");
    headList.add("1111");
    mHeadViewAdapter.setmLists(headList);
    mHeadViewPager.setAdapter(mHeadViewAdapter);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });
  }
Esempio n. 13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tabs = (TabLayout) findViewById(R.id.tabs);

    List<String> titles = new ArrayList<>();
    List<Fragment> fragments = new ArrayList<>();

    String titlec = "职业生涯";
    tabs.addTab(tabs.newTab().setText(titlec));
    titles.add(titlec);
    Fragment fragment = new CareerF();
    fragments.add(fragment);

    String titled = "日记";
    tabs.addTab(tabs.newTab().setText(titled));
    titles.add(titled);
    Fragment fragmentd = new Diary();
    fragments.add(fragmentd);

    String titleb = "亲友生日";
    tabs.addTab(tabs.newTab().setText(titleb));
    titles.add(titleb);
    Fragment fragmentb = new Birthday();
    fragments.add(fragmentb);

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    TabLayViewPAdapter adapter =
        new TabLayViewPAdapter(getSupportFragmentManager(), titles, fragments);

    viewPager.setAdapter(adapter);
    tabs.setupWithViewPager(viewPager);
    tabs.setTabsFromPagerAdapter(adapter);
    tabs.setOnTabSelectedListener(
        new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
            index = tab.getPosition();
          }

          @Override
          public void onTabUnselected(TabLayout.Tab tab) {}

          @Override
          public void onTabReselected(TabLayout.Tab tab) {}
        });

    final FloatingActionButton actionButton = (FloatingActionButton) findViewById(R.id.bt_auction);
    actionButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            switch (index) {
              case 0:
                UIHelper.startAddCareer(MainActivity.this);
                break;
              case 1:
                break;
              case 2:
                UIHelper.startAddBirthday(MainActivity.this);
                break;
            }
          }
        });
  }
Esempio n. 14
0
 private void setCategories(List<Category> categories) {
   adapter.setCategories(categories);
   tabs.setTabsFromPagerAdapter(adapter);
   tabs.setVisibility(categories.size() <= 1 ? View.GONE : View.VISIBLE);
 }