@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.people_org_pager, container, false);

    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout_org);
    tabLayout.addTab(tabLayout.newTab().setText("FOLLOWING"));
    tabLayout.addTab(tabLayout.newTab().setText("FOLOWERS"));
    tabLayout.addTab(tabLayout.newTab().setText("ORGANIZATIONS"));

    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    final ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager_org);
    final PagerOrgAdapter adapter =
        new PagerOrgAdapter(getActivity().getSupportFragmentManager(), tabLayout.getTabCount());
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(2);

    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setOnTabSelectedListener(
        new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
          }

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

          @Override
          public void onTabReselected(TabLayout.Tab tab) {}
        });
    return view;
  }
Example #2
0
  private void initTabView() {

    tabTiles = ResourcesUtils.getStringArray(this, R.array.tabItemName);
    tabItemDrawableNormal =
        new int[] {
          R.drawable.ic_tab_home_normal,
          R.drawable.ic_tab_classification_normal,
          R.drawable.ic_tab_car_normal,
          R.drawable.ic_tab_personal_normal
        };
    tabItemDrawableSelected =
        new int[] {
          R.drawable.ic_tab_home_selected,
          R.drawable.ic_tab_classification_selected,
          R.drawable.ic_tab_car_selected,
          R.drawable.ic_tab_personal_selected
        };

    final HomeActFragAdpter fragAdapter =
        new HomeActFragAdpter(getSupportFragmentManager(), this, tabTiles, tabItemDrawableNormal);
    viewPager_content.setAdapter(fragAdapter);
    layout_buttom_tab.setupWithViewPager(viewPager_content);
    tabCount = layout_buttom_tab.getTabCount();
    for (int i = 0; i < tabCount; i++) {
      TabLayout.Tab tab = layout_buttom_tab.getTabAt(i);
      if (tab != null) {
        tab.setCustomView(fragAdapter.getTabView(i));
      }
    }
    viewPager_content.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            for (int i = 0; i < tabCount; i++) {
              TabLayout.Tab tab = layout_buttom_tab.getTabAt(i);
              AppCompatTextView textView = (AppCompatTextView) tab.getCustomView();
              if (i == position) {
                fragAdapter.changeSelecteTabColor(textView, tabItemDrawableSelected[i], true);
              } else {
                fragAdapter.changeSelecteTabColor(textView, tabItemDrawableNormal[i], false);
              }
            }
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    viewPager_content.setCurrentItem(0);
    fragAdapter.changeSelecteTabColor(
        (AppCompatTextView) layout_buttom_tab.getTabAt(0).getCustomView(),
        tabItemDrawableSelected[0],
        true);
  }
Example #3
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   tabLayout = (TabLayout) findViewById(R.id.tablayout);
   viewPager = (ViewPager) findViewById(R.id.viewpager);
   setupviewpager(viewPager);
   tabLayout.setupWithViewPager(viewPager);
   for (int i = 0; i < tabLayout.getTabCount(); i++) {
     tabLayout.getTabAt(i).setIcon(tab_icons[i]);
   }
 }
Example #4
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);
    }
  }
Example #5
0
  public void onNextLibraryUpdate(List<Category> categories, Map<Integer, List<Manga>> mangas) {
    boolean hasMangasInDefaultCategory = mangas.get(0) != null;
    int activeCat = adapter.categories != null ? viewPager.getCurrentItem() : activeCategory;

    if (hasMangasInDefaultCategory) {
      setCategoriesWithDefault(categories);
    } else {
      setCategories(categories);
    }
    // Restore active category
    viewPager.setCurrentItem(activeCat, false);
    if (tabs.getTabCount() > 0) {
      TabLayout.Tab tab = tabs.getTabAt(viewPager.getCurrentItem());
      if (tab != null) tab.select();
    }

    // Send the mangas to child fragments after the adapter is updated
    EventBus.getDefault().postSticky(new LibraryMangasEvent(mangas));
  }
Example #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_test);
    Intent i = getIntent();

    doctor = (Doctor) i.getSerializableExtra("doc_details");

    TextView name = (TextView) findViewById(R.id.detail_name);
    name.setText(doctor.getDoctor_name());
    TextView category = (TextView) findViewById(R.id.detail_field);
    category.setText(doctor.getCaregory());

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText("Details"));
    tabLayout.addTab(tabLayout.newTab().setText("Chambers"));
    tabLayout.addTab(tabLayout.newTab().setText("Comment"));

    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    final ViewPagerTabFragmentAdapter adapter =
        new ViewPagerTabFragmentAdapter(
            doctor, getSupportFragmentManager(), tabLayout.getTabCount());
    viewPager.setAdapter(adapter);

    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

    tabLayout.setOnTabSelectedListener(
        new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
          }

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

          @Override
          public void onTabReselected(TabLayout.Tab tab) {}
        });
  }
  private void initData() {
    int size = mTitleArr.length;
    mViewList = new ArrayList<>(size);
    // 初始化 View 列表
    for (int i = 0; i < size; i++) {
      View view = LayoutInflater.from(this).inflate(R.layout.item_tablayoutdemo2_vp, null);
      TextView tv = (TextView) view.findViewById(R.id.tv_text);
      tv.setText(mTitleArr[i]);
      mViewList.add(view);
    }
    mAdapter = new TabLayoutDemo2PagerAdapter(mViewList);

    // 填充 ViewPager
    mContentVP.setAdapter(mAdapter);
    mTitleTL.setupWithViewPager(mContentVP);
    size = mTitleTL.getTabCount();
    for (int i = 0; i < size; i++) {
      TabLayout.Tab tab = mTitleTL.getTabAt(i);
      if (tab != null) {
        tab.setText(mTitleArr[i]);
      }
    }
    mContentVP.setCurrentItem(1);
  }
 public void selectFirstTab(View view) {
   if (mTabLayout.getTabCount() > 0) {
     mViewPager.setCurrentItem(0);
   }
 }
Example #9
0
 public void setupTabLayout() {
   for (int i = 0; i < tabLayout.getTabCount(); i++) {
     tabLayout.getTabAt(i).setCustomView(adapter.getTabView(i));
   }
 }