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

效果图如下:

相关推荐
书弋江山16 分钟前
flutter 跨平台编码库 protobuf 工具使用
android·flutter
来来走走3 小时前
Flutter开发 webview_flutter的基本使用
android·flutter
Jerry说前后端3 小时前
Android 组件封装实践:从解耦到架构演进
android·前端·架构
louisgeek4 小时前
Android OkHttp Interceptor
android
大王派来巡山的小旋风4 小时前
Kotlin基本用法三
android·kotlin
Jerry说前后端5 小时前
Android 移动端 UI 设计:前端常用设计原则总结
android·前端·ui
bytebeats5 小时前
Jetpack Compose 1.9: 核心新特性简介
android·android jetpack
Icey_World5 小时前
Mysql笔记-错误条件\处理程序
android
大王派来巡山的小旋风6 小时前
Kotlin基本用法之集合(一)
android·程序员·kotlin
用户2018792831676 小时前
智能广播系统(RemoteCallbackList)的诞生
android