解决方法如下:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
/**
* 自定义加粗的TextView
* https://www.jianshu.com/p/2ed23c25b095
* tv.getPaint().setStyle(Paint.Style.FILL_AND_STROKRE)
* tv.getPaint().setStrokeWidth(0.7)
* 另外textStype="bold" 太粗
*/
public class BoldTextView extends AppCompatTextView {
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) {
getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
getPaint().setStrokeWidth(0.7f);
super.onDraw(canvas);
}
}
效果图如下: