@Override
 public void onDetachedFromWindow() {
   super.onDetachedFromWindow();
   if (mTabSelector != null) {
     removeCallbacks(mTabSelector);
   }
 }
 @Override
 public void onAttachedToWindow() {
   super.onAttachedToWindow();
   if (mTabSelector != null) {
     // Re-post the selector we saved
     post(mTabSelector);
   }
 }
  @Override
  protected void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Action bar can change size on configuration changes.
    // Reread the desired height from the theme-specified style.
    TypedArray a =
        getContext()
            .obtainStyledAttributes(null, R.styleable.SherlockActionBar, R.attr.actionBarStyle, 0);
    setContentHeight(a.getLayoutDimension(R.styleable.SherlockActionBar_height, 0));
    a.recycle();
  }
  @Override
  public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY;
    setFillViewport(lockedExpanded);

    final int childCount = mTabLayout.getChildCount();
    if (childCount > 1 && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) {
      if (childCount > 2) {
        mMaxTabWidth = (int) (MeasureSpec.getSize(widthMeasureSpec) * 0.4f);
      } else {
        mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
      }
    } else {
      mMaxTabWidth = -1;
    }

    heightMeasureSpec = MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY);

    final boolean canCollapse = !lockedExpanded && mAllowCollapse;

    if (canCollapse) {
      // See if we should expand
      mTabLayout.measure(MeasureSpec.UNSPECIFIED, heightMeasureSpec);
      if (mTabLayout.getMeasuredWidth() > MeasureSpec.getSize(widthMeasureSpec)) {
        performCollapse();
      } else {
        performExpand();
      }
    } else {
      performExpand();
    }

    final int oldWidth = getMeasuredWidth();
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    final int newWidth = getMeasuredWidth();

    if (lockedExpanded && oldWidth != newWidth) {
      // Recenter the tab display if we're at a new (scrollable) size.
      setTabSelected(mSelectedTabIndex);
    }
  }