Skip to content

Commit

Permalink
改ColorTextView 为 TabColorTextView ,避免干扰
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzhengsr committed Jan 15, 2020
1 parent 21e78f6 commit 01ce2f7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 34 deletions.
10 changes: 5 additions & 5 deletions TAB_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- **shape 或者 bitmap 等资源**
- **自定义功能**
- **放大Item效果,与上述效果可共用**
- **颜色渐变效果,需要使用 ColorTextView 控件,与上述效果可共用**
- **颜色渐变效果,需要使用 TabColorTextView 控件,与上述效果可共用**


### 1、正常使用
Expand Down Expand Up @@ -85,7 +85,7 @@ private void rectFlow(){
```
可以看到,只需要设置 adapter 就行了,需要注意的是你要传入子控件的 layout,这样方便你自定义你的布局,比如添加一个红点点。

如果你需要使用颜色渐变的效果,TextView 可以使用 ColorTextView 就可以了。
如果你需要使用颜色渐变的效果,TextView 可以使用 TabColorTextView 就可以了。


### 2、结合Viewpager
Expand All @@ -109,8 +109,8 @@ flowLayout.setViewPager(...) 即可.
* @param viewPager
* @param textId view 中 textview 的id
* @param selectedIndex 默认选中的item,初始值为0,也可以从第二页或者其他 位置
* @param unselectedColor 没有选中的颜色 ColorTextView 中失效
* @param selectedColor 选中的颜色 ColorTextView 中失效
* @param unselectedColor 没有选中的颜色 TabColorTextView 中失效
* @param selectedColor 选中的颜色 TabColorTextView 中失效
*/
public void setViewPager(ViewPager viewPager, int textId, int selectedIndex, int unselectedColor, int selectedColor) {
Expand Down Expand Up @@ -223,7 +223,7 @@ private void resFlow(){
|tab_item_autoScale|boolean|开启放大缩小的效果|
|tab_scale_factor|float|放大倍数|

**ColorTextView**
**TabColorTextView**

| 名称 | 类型 |说明 |
|---|---|---|
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_color_msg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.zhengsr.tablib.view.ColorTextView
<com.zhengsr.tablib.view.TabColorTextView
android:id="@+id/item_text"
android:layout_width="wrap_content"
app:layout_constraintTop_toTopOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.widget.TextView;

import com.zhengsr.tablib.R;

Expand All @@ -24,7 +19,7 @@
* Describe: 颜色渐变类
*/

public class ColorTextView extends AppCompatTextView {
public class TabColorTextView extends AppCompatTextView {
private static final String TAG = "ColorTextView";
/**
* const
Expand All @@ -42,22 +37,22 @@ public class ColorTextView extends AppCompatTextView {
private int mDecection = DEC_LEFT;

private boolean isUseUserColor = false;
public ColorTextView(Context context) {
public TabColorTextView(Context context) {
this(context,null);
}

public ColorTextView(Context context, AttributeSet attrs) {
public TabColorTextView(Context context, AttributeSet attrs) {
this(context, attrs,0);

setIncludeFontPadding(false);

}

public ColorTextView(Context context, AttributeSet attrs, int defStyleAttr) {
public TabColorTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ColorTextView);
mDefaultColor = ta.getColor(R.styleable.ColorTextView_colortext_default_color, Color.GRAY);
mChangeColor = ta.getColor(R.styleable.ColorTextView_colortext_change_color,Color.WHITE);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TabColorTextView);
mDefaultColor = ta.getColor(R.styleable.TabColorTextView_colortext_default_color, Color.GRAY);
mChangeColor = ta.getColor(R.styleable.TabColorTextView_colortext_change_color,Color.WHITE);
ta.recycle();
mPaint = new Paint();
mPaint.setAntiAlias(true);
Expand Down
26 changes: 11 additions & 15 deletions tablib/src/main/java/com/zhengsr/tablib/view/action/BaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.TextView;
Expand All @@ -21,13 +20,10 @@
import com.zhengsr.tablib.bean.TabBean;
import com.zhengsr.tablib.bean.TabTypeEvaluator;
import com.zhengsr.tablib.bean.TabValue;
import com.zhengsr.tablib.utils.ViewPagerHelperUtils;
import com.zhengsr.tablib.view.ColorTextView;
import com.zhengsr.tablib.view.TabColorTextView;
import com.zhengsr.tablib.view.adapter.TabFlowAdapter;
import com.zhengsr.tablib.view.flow.TabFlowLayout;

import java.lang.reflect.Field;

/**
* @author by zhengshaorui on 2019/10/8
* Describe: 绘制基类
Expand Down Expand Up @@ -91,9 +87,9 @@ public void config(TabFlowLayout parentView) {
mOffset = mTabWidth * 1.0f / child.getMeasuredWidth();
if (mTextViewId != -1) {
View textView = child.findViewById(mTextViewId);
if (textView instanceof ColorTextView) {
if (textView instanceof TabColorTextView) {
isColorText = true;
ColorTextView colorTextView = (ColorTextView) textView;
TabColorTextView colorTextView = (TabColorTextView) textView;
colorTextView.setTextColor(colorTextView.getChangeColor());
}
if (textView instanceof TextView){
Expand Down Expand Up @@ -166,15 +162,15 @@ public void clearColorText() {
int childCount = mParentView.getChildCount();
for (int i = 0; i < childCount; i++) {
View view = mParentView.getChildAt(i);
ColorTextView textview = view.findViewById(mTextViewId);
TabColorTextView textview = view.findViewById(mTextViewId);
if (textview != null) {
textview.setTextColor(textview.getDefaultColor());
}

}

View view = mParentView.getChildAt(mCurrentIndex);
ColorTextView colorTextView = view.findViewById(mTextViewId);
TabColorTextView colorTextView = view.findViewById(mTextViewId);
if (colorTextView != null) {
colorTextView.setTextColor(colorTextView.getChangeColor());
}
Expand Down Expand Up @@ -234,10 +230,10 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
if (mTextViewId != -1 && isColorText) {
View leftView = curView.findViewById(mTextViewId);
View rightView = transView.findViewById(mTextViewId);
ColorTextView colorLeft = (ColorTextView) leftView;
ColorTextView colorRight = (ColorTextView) rightView;
colorLeft.setprogress(1 - positionOffset, ColorTextView.DEC_RIGHT);
colorRight.setprogress(positionOffset, ColorTextView.DEC_LEFT);
TabColorTextView colorLeft = (TabColorTextView) leftView;
TabColorTextView colorRight = (TabColorTextView) rightView;
colorLeft.setprogress(1 - positionOffset, TabColorTextView.DEC_RIGHT);
colorRight.setprogress(positionOffset, TabColorTextView.DEC_LEFT);
}
}
}
Expand Down Expand Up @@ -434,9 +430,9 @@ public void chooseIndex(int lastIndex,int curIndex){
mOffset = mTabWidth * 1.0f / child.getMeasuredWidth();
if (mTextViewId != -1) {
View textView = child.findViewById(mTextViewId);
if (textView instanceof ColorTextView) {
if (textView instanceof TabColorTextView) {
isColorText = true;
ColorTextView colorTextView = (ColorTextView) textView;
TabColorTextView colorTextView = (TabColorTextView) textView;
colorTextView.setTextColor(colorTextView.getChangeColor());
}
if (textView instanceof TextView){
Expand Down
2 changes: 1 addition & 1 deletion tablib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</declare-styleable>

<!--文件渐变属性-->
<declare-styleable name="ColorTextView">
<declare-styleable name="TabColorTextView">
<attr name="colortext_default_color" format="color|reference"/> <!--默认颜色-->
<attr name="colortext_change_color" format="color|reference"/> <!--渐变颜色-->
</declare-styleable>
Expand Down

0 comments on commit 01ce2f7

Please sign in to comment.