11package com .hjq .shape .span ;
22
33import android .graphics .Canvas ;
4+ import android .graphics .Color ;
45import android .graphics .Paint ;
6+ import android .support .annotation .ColorInt ;
57import android .support .annotation .NonNull ;
68import android .text .SpannableStringBuilder ;
79import android .text .Spanned ;
@@ -23,6 +25,9 @@ public class StrokeFontSpan extends CommonFontSpan {
2325 private int mTextStrokeColor ;
2426 private int mTextStrokeSize ;
2527
28+ /** 文本颜色 */
29+ private int mTextSolidColor ;
30+
2631 /**
2732 * 构建一个文字描边的 Spannable 对象
2833 */
@@ -58,10 +63,22 @@ public void onDraw(@NonNull Canvas canvas, @NonNull Paint paint, CharSequence te
5863 // 设置粗体
5964 //mStrokePaint.setFakeBoldText(true);
6065 mStrokePaint .setColor (mTextStrokeColor );
66+ // 绘制文本描边
6167 canvas .drawText (text , start , end , x , y , mStrokePaint );
68+
69+ // 绘制文本内容
70+ if (mTextSolidColor != Color .TRANSPARENT ) {
71+ paint .setColor (mTextSolidColor );
72+ canvas .drawText (text , start , end , x , y , paint );
73+ }
74+ }
75+
76+ public StrokeFontSpan setTextSolidColor (@ ColorInt int color ) {
77+ mTextSolidColor = color ;
78+ return this ;
6279 }
6380
64- public StrokeFontSpan setTextStrokeColor (int color ) {
81+ public StrokeFontSpan setTextStrokeColor (@ ColorInt int color ) {
6582 mTextStrokeColor = color ;
6683 return this ;
6784 }
0 commit comments