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

效果图如下:

相关推荐
我命由我123451 小时前
Android Jetpack Compose 开发问题:Unresolved reference ‘Icons‘.
android·java-ee·kotlin·android studio·android jetpack·android-studio·android runtime
爱笑鱼1 小时前
Android 系统启动机制(六):Zygote 创建 App 为什么走 Socket?哪些是源码事实,哪些是架构解释?
android·linux
AI2中文网1 小时前
安卓模拟器启动卡在进度条?两步解决硬件加速冲突
android
IT毕设实战小研1 小时前
基于大数据的DAX40成分股金融新闻情感趋势可视化分析
android·大数据·python·考研·金融·课程设计
Android-Flutter2 小时前
flutter async/await 详解
android·flutter
步行cgn2 小时前
Spring Boot 中的 YAML 完全指南
android·spring boot·firefox
事圆则缓3 小时前
Java 常见数据结构与 Android 使用场景
android·java·数据结构
RisunJan3 小时前
Android 高频面试题与解答
android
MyBili3 小时前
【安卓开发/搞机】快图浏览(QuickPic)技术解析:为何这款3MB应用仍是本地图库的性能天花板?
android·app·安卓·文件管理·相册·看图软件·手机相册
事圆则缓4 小时前
Kotlin 高阶工程化与 Android 深入实践
android·开发语言·kotlin