@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();
          }
        });
  }
Beispiel #2
0
 public void setLogoDescription(int i) {
     setLogoDescription(getContext().getText(i));
 }