android 全局换字体,Android 全局替换字体

1. 替换全局字体

需要引入依赖

// 替换全局字体使用

api 'com.android.support:support-v13:28.0.0'

在 res 目录下创建一个 font 目录,将用到的字体复制进去,然后再创建一个字体的xml。

6d51190d4456

替换字体01.jpg

xmlns:app="http://schemas.android.com/apk/res-auto">

android:font="@font/pop_ttf"

android:fontStyle="normal"

android:fontWeight="400"

app:font="@font/pop_ttf"

app:fontStyle="normal"

app:fontWeight="400" />

android:font="@font/pop_ttf"

android:fontStyle="italic"

android:fontWeight="400"

app:font="@font/pop_ttf"

app:fontStyle="italic"

app:fontWeight="400" />

在主题中引用

@font/pop_font

2. 在实际使用中,发现对 RadioButton 不起作用,所以自定义一个 RadioButton 单独对其进行处理;

添加属性;

继承 RadioButton;

class MyRadioButton @JvmOverloads constructor(

context: Context,

attrs: AttributeSet? = null,

defStyleAttr: Int = 0

) : RadioButton(context, attrs, defStyleAttr) {

private var textFont: Int = -1

init {

val typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyRadioButton) //获取我们定义的属性

textFont = typedArray.getResourceId(R.styleable.MyRadioButton_textFont, -1)

initView()

typedArray.recycle()

}

private fun initView() {

if (-1 != textFont) {

paint.isAntiAlias = true

val font = ResourcesCompat.getFont(context, textFont)

paint.typeface = font

}

}

}

使用;

android:id="@+id/rb_mine"

style="@style/MainBtmTabRBtn"

android:text="我的"

app:textFont="@font/pop_font" />

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值