Esempio n. 1
0
  public void notifyDataSetChanged() {

    tabsContainer.removeAllViews();

    tabCount = pager.getAdapter().getCount();

    for (int i = 0; i < tabCount; i++) {

      if (pager.getAdapter() instanceof IconTabProvider) {
        addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
      } else {
        //                addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
        addCustomTab(i, pager.getAdapter().getPageTitle(i).toString());
      }
    }

    updateTabStyles();

    getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

              @SuppressWarnings("deprecation")
              @SuppressLint("NewApi")
              @Override
              public void onGlobalLayout() {

                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                  getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                  getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                currentPosition = pager.getCurrentItem();
                scrollToChild(currentPosition, 0);
              }
            });
  }
 public void setTabPaddingLeftRight(int paddingPx) {
   this.tabPadding = paddingPx;
   updateTabStyles();
 }
 public void setTypeface(Typeface typeface, int style) {
   this.tabTypeface = typeface;
   this.tabTypefaceStyle = style;
   updateTabStyles();
 }
 public void setTextColorResource(int resId) {
   this.tabTextColor = getResources().getColor(resId);
   updateTabStyles();
 }
 public void setTextColor(int textColor) {
   this.tabTextColor = textColor;
   updateTabStyles();
 }
 public void setTextSize(int textSizePx) {
   this.tabTextSize = textSizePx;
   updateTabStyles();
 }
 // set Tab Gravity and call updateTabStyles() to refresh view
 public void setTabGravity(int tabGravity) {
   this.tabGravity = tabGravity;
   updateTabStyles();
 }