继承TextView 重写onDraw,在super.onDraw(canvas)方法前修改画笔宽度
public class BoldTextView extends TextView {
public BoldTextView(Context context) {
super(context);
}
public BoldTextView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public BoldTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
//获取当前控件的画笔
TextPaint paint = getPaint();
//设置画笔的描边宽度值
paint.setStrokeWidth(2.2f);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
super.onDraw(canvas);
}
}
网友评论