我找到了这个解决方案,可以在Custom TextView {{3}}
中添加大纲@Override
public void onDraw(Canvas canvas) {
Log.i("LOG", "onDraw textView"); // loop
final ColorStateList textColor = getTextColors();
TextPaint paint = this.getPaint();
paint.setStyle(Style.STROKE);
paint.setStrokeJoin(Join.ROUND);
paint.setStrokeMiter(10);
this.setTextColor(strokeColor);
paint.setStrokeWidth(strokeWidth);
super.onDraw(canvas);
paint.setStyle(Style.FILL);
setTextColor(textColor); // second call causes infinite loop
super.onDraw(canvas);
}
它绘制正常,但它已循环播放(onDraw
被无限调用)
循环是在setTextColor
中调用onDraw
方法两次引起的,如果你只调用一次然后一切正常(但你只得到一种颜色的文字和大纲)
如何修复此示例或获得相同结果的更好解决方案?