private View getNeededView(int position) { if (mTabProvider != null && mTabProvider instanceof TitleIconTabProvider) { final int imageViewId = ((TitleIconTabProvider) mTabProvider).getTextOrImageViewId(); return mNiceTabStrip.getChildAt(position).findViewById(imageViewId); } else { return mNiceTabStrip.getChildAt(position); } }
private void scrollToTab(int position, int positionOffset) { final int tabStripChildCount = mNiceTabStrip.getChildCount(); if (tabStripChildCount == 0 || position < 0 || position >= tabStripChildCount) { return; } View selectedTab = mNiceTabStrip.getChildAt(position); if (selectedTab != null) { int targetScrollX = selectedTab.getLeft() + positionOffset; if (mNiceTabStrip.isTabSelectedCenter()) { targetScrollX -= (mNiceTabStrip.getChildAt(0).getWidth() - selectedTab.getWidth()) / 2; } else if (position > 0 || positionOffset > 0) { targetScrollX -= mTabOffset; } scrollTo(targetScrollX, 0); } }
/** * Sets divider show hide. * * @param showDivider show hide. */ public void setShowDivider(boolean showDivider) { mNiceTabStrip.setShowDivider(showDivider); postDelayed( new Runnable() { @Override public void run() { scrollToTab(mViewPager.getCurrentItem(), 0); } }, 100); }
void changeTabLayoutPadding(boolean tabSelectedCenter, boolean isTabDistributeEvenly) { if (tabSelectedCenter) { final int paddingLeft, paddingRight; if (isTabDistributeEvenly) { paddingLeft = (getWidth() - mNiceTabStrip.getTabEvenlyWidth()) / 2; paddingRight = (getWidth() - mNiceTabStrip.getTabEvenlyWidth()) / 2; } else { paddingLeft = (getWidth() - mNiceTabStrip.getFirstTabWidth()) / 2; paddingRight = (getWidth() - mNiceTabStrip.getLastTabWidth()) / 2; } mUserSetPadding = false; setPadding(paddingLeft, getPaddingTop(), paddingRight, getPaddingBottom()); mUserSetPadding = true; setClipToPadding(false); } else { mUserSetPadding = false; setPadding(mCachedPaddingLeft, getPaddingTop(), mCachedPaddingRight, getPaddingBottom()); mUserSetPadding = true; } }
/** * Sets weather tab distribute evenly, if true, every tab width will set to the most wide tab * width. */ public void setDistributeEvenly(final boolean distributeEvenly) { mNiceTabStrip.setTabDistributeEvenly(distributeEvenly); postDelayed( new Runnable() { @Override public void run() { scrollToTab(mViewPager.getCurrentItem(), 0); } }, 100); }
/** Sets weather selected tab layout in center. */ public void setTabSelectedCenter(final boolean tabSelectedCenter) { mNiceTabStrip.setTabSelectedCenter(tabSelectedCenter); postDelayed( new Runnable() { @Override public void run() { scrollToTab(mViewPager.getCurrentItem(), 0); } }, 100); }
/** Populate TabStrip tabs. */ private void populateTabStrip() { mNiceTabStrip.removeAllViews(); final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); int count = adapter.getCount(); for (int i = 0; i < count; i++) { View tabView; if (mTabProvider != null) { tabView = mTabProvider.createTabView(mNiceTabStrip, i, adapter); } else { tabView = createDefaultTabView(i); } tabView.setOnClickListener(tabClickListener); mNiceTabStrip.addView(tabView); } }
/** * Sets blurred view. * * @param blurredView the view to be blurred. (Set null to cancel blur) * @param blurredBackgroundColor the view's background color. (if blurredView's background is * color, give the color to me, if is not color, give 0{@link * android.graphics.Color#TRANSPARENT} to me, if blurredView's background is null, give a * proper color to me, i.e blurredView's parent background color or window's background color. */ public void setBlurredView(View blurredView, int blurredBackgroundColor) { if (blurredView != null) { mUserSetBackground = false; setBackgroundDrawable(null); mUserSetBackground = true; } else { mUserSetBackground = false; setBackgroundDrawable(mCachedBackground); mUserSetBackground = true; } mNiceTabStrip.setBlurredView(blurredView, blurredBackgroundColor); }
/** * Gets tab badge text. * * @param position tab position. * @return null(small badge, or tab has no badge with given position) or badge text. */ public String getBadgeText(int position) { return mNiceTabStrip.getBadgeText(position); }
/** * Remove tab badge with given position. * * @param position tab position. * @return the badge or null(no position or no badges). */ public Badge removeBadge(int position) { return mNiceTabStrip.removeBadge(position); }
/** * Sets tab badge(small size). * * @param position tab position. */ public void setBadgeSmall(int position) { mNiceTabStrip.setBadgeSmall(position); }
/** * 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 setIndicatorColors(int... colors) { mNiceTabStrip.setIndicatorColors(colors); }
/** Sets indicator underline divider draw order. */ public void setDrawOrder(NiceTabStrip.DrawOrder drawOrder) { mNiceTabStrip.setDrawOrder(drawOrder); }
public void invalidateBlur() { mNiceTabStrip.invalidate(); }
/** * Sets the blur overlay color. * * @param color the blur overlay color. */ public void setOverlayColor(int color) { mNiceTabStrip.setOverlayColor(color); }
/** * Sets the blur down sample factor. * * @param factor the blur down sample factor. */ public void setDownSampleFactor(int factor) { mNiceTabStrip.setDownSampleFactor(factor); }
/** * Sets the blur radius. * * @param radius the blur radius. */ public void setBlurRadius(int radius) { mNiceTabStrip.setBlurRadius(radius); }
/** Clears all tab badges. */ public void clearBadge() { mNiceTabStrip.clearBadge(); }
/** * Sets underline show hide. * * @param showUnderline show hide. */ public void setShowUnderline(boolean showUnderline) { mNiceTabStrip.setShowUnderline(showUnderline); }
/** * Register a callback to be invoked when indicator color changed. * * @param listener The callback that will run */ public void setOnIndicatorColorChangedListener( NiceTabStrip.OnIndicatorColorChangedListener listener) { mNiceTabStrip.setOnIndicatorColorChangedListener(listener); }
/** * Set the custom {@link NiceTabStrip.TabStripColorize} 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 setTabStripColorize(NiceTabStrip.TabStripColorize tabColorize) { mNiceTabStrip.setTabStripColorize(tabColorize); }
/** Reset all tab to defaults and select current page tab. */ private void resetTabStrip() { int childCount = mNiceTabStrip.getChildCount(); int selectedPosition = mViewPager.getCurrentItem(); for (int i = 0; i < childCount; i++) { View view = getNeededView(i); switch (mTabMode) { case TITLE_ONLY: { ((TextView) view) .setTextColor( i == selectedPosition ? mTabColorize.getSelectedTabColor(i) : mTabColorize.getDefaultTabColor(i)); break; } case ICON_ONLY: { Drawable drawable = ((ImageView) view).getDrawable(); if (mIconCrossFade && drawable instanceof CrossFadeDrawable) { // tintDrawable(((CrossFadeDrawable) // drawable).getFading().mutate(), mTabColorize.getSelectedTabColor(i)); tintDrawable( ((CrossFadeDrawable) drawable).getFading(), mTabColorize.getSelectedTabColor(i)); // tintDrawable(((CrossFadeDrawable) // drawable).getBase().mutate(), mTabColorize.getDefaultTabColor(i)); tintDrawable( ((CrossFadeDrawable) drawable).getBase(), mTabColorize.getDefaultTabColor(i)); crossFadeDrawable(drawable, i == selectedPosition ? 1f : 0f); } break; } case BOTH: { final int color = i == selectedPosition ? mTabColorize.getSelectedTabColor(i) : mTabColorize.getDefaultTabColor(i); ((TextView) view).setTextColor(color); Drawable drawable = ((TextView) view).getCompoundDrawables()[1]; if (mIconCrossFade && drawable instanceof CrossFadeDrawable) { // tintDrawable(((CrossFadeDrawable) // drawable).getFading().mutate(), mTabColorize.getSelectedTabColor(i)); tintDrawable( ((CrossFadeDrawable) drawable).getFading(), mTabColorize.getSelectedTabColor(i)); // tintDrawable(((CrossFadeDrawable) // drawable).getBase().mutate(), mTabColorize.getDefaultTabColor(i)); tintDrawable( ((CrossFadeDrawable) drawable).getBase(), mTabColorize.getDefaultTabColor(i)); crossFadeDrawable(drawable, i == selectedPosition ? 1f : 0f); } else { // tintDrawable(drawable.mutate(), color); tintDrawable(drawable, color); } break; } } view.setSelected(i == selectedPosition); } }
/** * Sets indicator show hide. * * @param showIndicator show hide. */ public void setShowIndicator(boolean showIndicator) { mNiceTabStrip.setShowIndicator(showIndicator); }
@Override protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { super.onSizeChanged(width, height, oldWidth, oldHeight); changeTabLayoutPadding( mNiceTabStrip.isTabSelectedCenter(), mNiceTabStrip.isTabDistributeEvenly()); }
/** * Sets tab badge(normal size). * * @param position tab position. * @param text tab badge text, if text is null, do nothing. */ public void setBadge(int position, String text) { mNiceTabStrip.setBadge(position, text); }
@Override protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) { mNiceTabStrip.invalidate(); }
/** * Sets the colors to be used for tab dividers. These colors are treated as a circular array. * Providing one color will mean that all tabs are indicated with the same color. */ public void setDividerColors(int... colors) { mNiceTabStrip.setDividerColors(colors); }