private void scrollToTab(int tabIndex, int positionOffset) {
    final int tabStripChildCount = mTabStrip.getChildCount();
    if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
      return;
    }

    View selectedChild = mTabStrip.getChildAt(tabIndex);
    if (selectedChild != null) {
      int targetScrollX = selectedChild.getLeft() + positionOffset;

      if (tabIndex > 0 || positionOffset > 0) {
        // If we're not at the first child and are mid-scroll, make sure we obey the offset
        targetScrollX -= mTitleOffset;
      }

      scrollTo(targetScrollX, 0);
    }
  }
  /**
   * Sets the associated view pager. Note that the assumption here is that the pager content (number
   * of tabs and tab titles) does not change after this call has been made.
   */
  public void setViewPager(ViewPager viewPager) {
    mTabStrip.removeAllViews();

    mViewPager = viewPager;
    if (viewPager != null) {
      viewPager.setOnPageChangeListener(new InternalViewPagerListener());
      populateTabStrip();
    }
  }
  private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
      View tabView = null;
      TextView tabTitleView = null;

      if (mTabViewLayoutId != 0) {
        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
      }

      if (tabView == null) {
        tabView = createDefaultTabView(getContext());
      }

      if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        tabTitleView = (TextView) tabView;
      }

      if (mDistributeEvenly) {
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        lp.width = 0;
        lp.weight = 1;
      }

      tabTitleView.setTypeface(r_reg);

      tabTitleView.setText(adapter.getPageTitle(i));
      tabView.setOnClickListener(tabClickListener);
      String desc = mContentDescriptions.get(i, null);
      if (desc != null) {
        tabView.setContentDescription(desc);
      }

      mTabStrip.addView(tabView);
      if (i == mViewPager.getCurrentItem()) {
        tabView.setSelected(true);
      }

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector_text, null));
      } else {
        tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector_text));
      }
      tabTitleView.setTextSize(15);
    }
  }
 /**
  * Set the custom {@link TabColorizer} to be used.
  *
  * <p>If you only require simple custmisation then you can use {@link
  * #setSelectedIndicatorColors(int...)} to achieve similar effects.
  */
 public void setCustomTabColorizer(TabColorizer tabColorizer) {
   mTabStrip.setCustomTabColorizer(tabColorizer);
 }
 /**
  * Sets the colors to be used for indicating the selected tab. These colors are treated as a
  * circular array. Providing one color will mean that all tabs are indicated with the same color.
  */
 public void setSelectedIndicatorColors(int... colors) {
   mTabStrip.setSelectedIndicatorColors(colors);
 }