Android实现两种颜色的TextView
一. 效果
二、代码实现
2.1 自定义属性
<declare-styleable name="TwoColorTextView">
<attr name="originColor" format="color"/>
<attr name="changeColor" format="color"/>
</declare-styleable>
2.2 自定义View
通过继承TextView实现,之所以继承TextView 是共用一些现有的东西避免重复
package com.example.layoutdemo.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.example.layoutdemo.R;
public class TwoColorTextView extends TextView {
private int mOriginColor;
private int mChangeColor;
private <