Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions demo/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<item name="android:textColorSecondary">@color/secondary_text</item>
</style>

<style name="AppTheme.Main" parent="AppTheme">
</style>
<style name="AppTheme.Main" parent="AppTheme"></style>

<style name="AppTheme.NoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
Expand All @@ -22,5 +21,10 @@

<style name="RecyclerTabLayoutTheme.Basic"></style>

<style name="AppBarText">
<item name="android:textColor">@android:color/holo_red_dark</item>
<item name="android:textSize">11sp</item>
<item name="android:textStyle">bold</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class RecyclerTabLayout extends RecyclerView {
protected int mTabMinWidth;
protected int mTabMaxWidth;
protected int mTabTextAppearance;
protected int mTabSelectedTextAppearance;
protected int mTabSelectedTextColor;
protected boolean mTabSelectedTextColorSet;
protected int mTabPaddingStart;
Expand All @@ -63,12 +64,12 @@ public class RecyclerTabLayout extends RecyclerView {
protected int mIndicatorPosition;
protected int mIndicatorGap;
protected int mIndicatorScroll;
private int mOldPosition;
private int mOldScrollOffset;
protected float mOldPositionOffset;
protected float mPositionThreshold;
protected boolean mRequestScrollToTab;
protected boolean mScrollEanbled;
private int mOldPosition;
private int mOldScrollOffset;

public RecyclerTabLayout(Context context) {
this(context, null);
Expand Down Expand Up @@ -106,6 +107,9 @@ private void getAttributes(Context context, AttributeSet attrs, int defStyle) {
mTabTextAppearance = a.getResourceId(R.styleable.rtl_RecyclerTabLayout_rtl_tabTextAppearance,
R.style.rtl_RecyclerTabLayout_Tab);

mTabSelectedTextAppearance = a.getResourceId(R.styleable.rtl_RecyclerTabLayout_rtl_tabSelectedTextAppearance,
R.style.rtl_RecyclerTabLayout_Tab);

mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a
.getDimensionPixelSize(R.styleable.rtl_RecyclerTabLayout_rtl_tabPadding, 0);
mTabPaddingStart = a.getDimensionPixelSize(
Expand Down Expand Up @@ -175,6 +179,7 @@ public void setUpWithViewPager(ViewPager viewPager) {
DefaultAdapter adapter = new DefaultAdapter(viewPager);
adapter.setTabPadding(mTabPaddingStart, mTabPaddingTop, mTabPaddingEnd, mTabPaddingBottom);
adapter.setTabTextAppearance(mTabTextAppearance);
adapter.setTabSelectedTextAppearance(mTabSelectedTextAppearance);
adapter.setTabSelectedTextColor(mTabSelectedTextColorSet, mTabSelectedTextColor);
adapter.setTabMaxWidth(mTabMaxWidth);
adapter.setTabMinWidth(mTabMinWidth);
Expand Down Expand Up @@ -262,7 +267,7 @@ protected void scrollToTab(int position, float positionOffset, boolean fitIndica
if (position == 0) {
float indicatorGap = (nextView.getMeasuredWidth() - selectedView.getMeasuredWidth()) / 2;
mIndicatorGap = (int) (indicatorGap * positionOffset);
mIndicatorScroll = (int)((selectedView.getMeasuredWidth() + indicatorGap) * positionOffset);
mIndicatorScroll = (int) ((selectedView.getMeasuredWidth() + indicatorGap) * positionOffset);

} else {
float indicatorGap = (nextView.getMeasuredWidth() - selectedView.getMeasuredWidth()) / 2;
Expand Down Expand Up @@ -358,6 +363,7 @@ protected boolean isLayoutRtl() {

protected static class RecyclerOnScrollListener extends OnScrollListener {

public int mDx;
protected RecyclerTabLayout mRecyclerTabLayout;
protected LinearLayoutManager mLinearLayoutManager;

Expand All @@ -367,8 +373,6 @@ public RecyclerOnScrollListener(RecyclerTabLayout recyclerTabLayout,
mLinearLayoutManager = linearLayoutManager;
}

public int mDx;

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
mDx += dx;
Expand Down Expand Up @@ -460,13 +464,13 @@ public ViewPager getViewPager() {
return mViewPager;
}

public void setCurrentIndicatorPosition(int indicatorPosition) {
mIndicatorPosition = indicatorPosition;
}

public int getCurrentIndicatorPosition() {
return mIndicatorPosition;
}

public void setCurrentIndicatorPosition(int indicatorPosition) {
mIndicatorPosition = indicatorPosition;
}
}

public static class DefaultAdapter
Expand All @@ -479,6 +483,7 @@ public static class DefaultAdapter
protected int mTabPaddingEnd;
protected int mTabPaddingBottom;
protected int mTabTextAppearance;
protected int mTabSelectedTextAppearance;
protected boolean mTabSelectedTextColorSet;
protected int mTabSelectedTextColor;
private int mTabMaxWidth;
Expand Down Expand Up @@ -523,6 +528,7 @@ public DefaultAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewTy
if (mTabSelectedTextColorSet) {
tabTextView.setTextColor(tabTextView.createColorStateList(
tabTextView.getCurrentTextColor(), mTabSelectedTextColor));

}
if (mTabBackgroundResId != 0) {
tabTextView.setBackgroundDrawable(
Expand All @@ -537,6 +543,9 @@ public void onBindViewHolder(DefaultAdapter.ViewHolder holder, int position) {
CharSequence title = getViewPager().getAdapter().getPageTitle(position);
holder.title.setText(title);
holder.title.setSelected(getCurrentIndicatorPosition() == position);
holder.title.setTextAppearance(holder.title.getContext(),
getCurrentIndicatorPosition() == position ?
mTabSelectedTextAppearance : mTabTextAppearance);
}

@Override
Expand All @@ -556,6 +565,10 @@ public void setTabTextAppearance(int tabTextAppearance) {
mTabTextAppearance = tabTextAppearance;
}

public void setTabSelectedTextAppearance(int tabSelectedTextAppearance) {
mTabSelectedTextAppearance = tabSelectedTextAppearance;
}

public void setTabSelectedTextColor(boolean tabSelectedTextColorSet,
int tabSelectedTextColor) {
mTabSelectedTextColorSet = tabSelectedTextColorSet;
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<attr name="rtl_tabBackground" format="reference"/>

<attr name="rtl_tabTextAppearance" format="reference"/>
<attr name="rtl_tabSelectedTextAppearance" format="reference" />
<attr name="rtl_tabSelectedTextColor" format="color"/>

<attr name="rtl_tabOnScreenLimit" format="integer"/>
Expand Down