TextView加粗字体太粗

解决方法如下:

java 复制代码
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);
    }
}

效果图如下:

相关推荐
用户20187928316711 分钟前
Android黑夜白天模式切换原理分析
android
芦半山36 分钟前
「幽灵调用」背后的真相:一个隐藏多年的Android原生Bug
android
卡尔特斯1 小时前
Android Kotlin 项目代理配置【详细步骤(可选)】
android·java·kotlin
ace望世界1 小时前
安卓的ViewModel
android
ace望世界1 小时前
kotlin的委托
android
CYRUS_STUDIO3 小时前
一文搞懂 Frida Stalker:对抗 OLLVM 的算法还原利器
android·逆向·llvm
zcychong4 小时前
ArrayMap、SparseArray和HashMap有什么区别?该如何选择?
android·面试
CYRUS_STUDIO4 小时前
Frida Stalker Trace 实战:指令级跟踪与寄存器变化监控全解析
android·逆向
ace望世界9 小时前
android的Parcelable
android
顾林海9 小时前
Android编译插桩之AspectJ:让代码像特工一样悄悄干活
android·面试·性能优化