<
中划线textview
>
上一篇

Xcode的模拟器删除(某个版本)
下一篇

Selector 非shape 设置大小

温故而知新,这次来实现一个中划线文本

利用TextView的api:

android.widget.TextView#getPaint

设置Paint的flag为中划线Paint.STRIKE_THRU_TEXT_FLAG

android.graphics.Paint#setFlags

完整代码:

public class StrikeThruTextView extends android.support.v7.widget.AppCompatTextView {
    public StrikeThruTextView(Context context) {
        super(context);
    }

    public StrikeThruTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public StrikeThruTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        super.onDraw(canvas);
    }
}

Top
Foot