예제 #1
0
 /**
  * Sets the colors to be used for each tab's selected state. These colors are treated as a
  * circular array. Providing one color will mean that all tabs are indicated with the same color.
  */
 public void setSelectedTabColors(int... colors) {
   mSelectedTabColors = colors;
   SimpleTabColorize simpleTabColorize = new SimpleTabColorize();
   simpleTabColorize.setDefaultTabColors(mDefaultTabColors);
   simpleTabColorize.setSelectedTabColors(colors);
   mTabColorize = simpleTabColorize;
   resetTabStrip();
 }
예제 #2
0
 /**
  * Set the custom {@link TabColorize} to be used, if set to null, then uses default TabColorize
  *
  * <p>If you only require simple customisation then you can use {@link
  * #setIndicatorColors(int...)} and {@link #setDividerColors(int...)} to achieve similar effects.
  */
 public void setTabColorize(TabColorize tabColorize) {
   if (tabColorize != null) {
     mTabColorize = tabColorize;
   } else {
     mTabColorize = new SimpleTabColorize();
     ((SimpleTabColorize) mTabColorize).setDefaultTabColors(mDefaultTabColors);
     ((SimpleTabColorize) mTabColorize).setSelectedTabColors(mSelectedTabColors);
   }
   resetTabStrip();
 }
예제 #3
0
  public NiceTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setHorizontalScrollBarEnabled(false);
    setFillViewport(true);
    setClipToPadding(false);

    mCachedPaddingLeft = getPaddingLeft();
    mCachedPaddingRight = getPaddingRight();
    mCachedBackground = getBackground();

    final DisplayMetrics dm = getResources().getDisplayMetrics();

    final float density = dm.density;

    final TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.NiceTabLayout, defStyle, 0);

    mTabMode =
        TabMode.fromInt(
            a.getInt(R.styleable.NiceTabLayout_ntlTabMode, TabMode.TITLE_ONLY.intValue));

    mTabColorBlendMode =
        TabColorBlendMode.fromInt(
            a.getInt(
                R.styleable.NiceTabLayout_ntlTabColorBlendMode,
                TabColorBlendMode.DEFAULT_SELECTED.intValue));

    mTabBackground = a.getResourceId(R.styleable.NiceTabLayout_ntlTabBackground, NO_ID);

    mTabOffset =
        a.getDimensionPixelSize(
            R.styleable.NiceTabLayout_ntlTabOffset, (int) (DEFAULT_TAB_OFFSET_DP * density));

    final int defaultTabColor =
        a.getColor(R.styleable.NiceTabLayout_ntlDefaultTabColor, DEFAULT_DEFAULT_TAB_COLOR);
    final int defaultTabColorsId =
        a.getResourceId(R.styleable.NiceTabLayout_ntlDefaultTabColors, NO_ID);
    mDefaultTabColors =
        (defaultTabColorsId == NO_ID)
            ? new int[] {defaultTabColor}
            : getResources().getIntArray(defaultTabColorsId);
    final int selectedTabColor =
        a.getColor(R.styleable.NiceTabLayout_ntlSelectedTabColor, DEFAULT_SELECTED_TAB_COLOR);
    final int selectedTabColorsId =
        a.getResourceId(R.styleable.NiceTabLayout_ntlSelectedTabColors, NO_ID);
    mSelectedTabColors =
        (selectedTabColorsId == NO_ID)
            ? new int[] {selectedTabColor}
            : getResources().getIntArray(selectedTabColorsId);

    final int padding = a.getDimensionPixelSize(R.styleable.NiceTabLayout_ntlTabPadding, -1);
    mTabPaddingTop =
        a.getDimensionPixelSize(
            R.styleable.NiceTabLayout_ntlTabPaddingTop,
            padding == -1 ? (int) (DEFAULT_TAB_PADDING_TOP_BOTTOM_DP * density) : 0);
    mTabPaddingBottom =
        a.getDimensionPixelSize(
            R.styleable.NiceTabLayout_ntlTabPaddingBottom,
            padding == -1 ? (int) (DEFAULT_TAB_PADDING_TOP_BOTTOM_DP * density) : 0);
    mTabPaddingLeft =
        a.getDimensionPixelSize(
            R.styleable.NiceTabLayout_ntlTabPaddingLeft,
            padding == -1 ? (int) (DEFAULT_TAB_PADDING_LEFT_RIGHT_DP * density) : 0);
    mTabPaddingRight =
        a.getDimensionPixelSize(
            R.styleable.NiceTabLayout_ntlTabPaddingRight,
            padding == -1 ? (int) (DEFAULT_TAB_PADDING_LEFT_RIGHT_DP * density) : 0);
    mTabViewLayoutId = a.getResourceId(R.styleable.NiceTabLayout_ntlTabViewLayoutId, NO_ID);
    mTabViewTextOrImageViewId =
        a.getResourceId(R.styleable.NiceTabLayout_ntlTabViewTextOrImageViewId, NO_ID);

    mDrawablePadding =
        a.getDimensionPixelSize(
            R.styleable.NiceTabLayout_ntlDrawablePadding,
            (int) (DEFAULT_DRAWABLE_PADDING_DP * density));
    mTextSize =
        a.getDimension(
            R.styleable.NiceTabLayout_ntlTextSize,
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP, dm));
    mTextAllCaps = a.getBoolean(R.styleable.NiceTabLayout_ntlTextAllCaps, DEFAULT_TEXT_ALL_CAPS);
    mTextStyle = a.getInt(R.styleable.NiceTabLayout_ntlTextStyle, Typeface.BOLD);

    mIconCrossFade =
        a.getBoolean(R.styleable.NiceTabLayout_ntlIconCrossFade, DEFAULT_ICON_CROSS_FADE);
    mIconTint = a.getBoolean(R.styleable.NiceTabLayout_ntlIconTint, DEFAULT_ICON_TINT);

    a.recycle();

    if (mTabViewLayoutId != NO_ID && mTabViewTextOrImageViewId != NO_ID) {
      setCustomTabView(mTabViewLayoutId, mTabViewTextOrImageViewId);
    }

    mTabColorize = new SimpleTabColorize();
    ((SimpleTabColorize) mTabColorize).setDefaultTabColors(mDefaultTabColors);
    ((SimpleTabColorize) mTabColorize).setSelectedTabColors(mSelectedTabColors);

    mNiceTabStrip = new NiceTabStrip(context, attrs);

    addView(
        mNiceTabStrip, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  }