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);
    }
}

效果图如下:

相关推荐
火柴就是我3 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
砖厂小工10 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心11 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心11 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker13 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴14 小时前
Android17 为什么重写 MessageQueue
android
阿巴斯甜1 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker1 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95271 天前
Andorid Google 登录接入文档
android
黄林晴2 天前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack