1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > android 全局换字体 Android 全局替换字体

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

时间:2023-04-09 17:47:30

相关推荐

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

1. 替换全局字体

需要引入依赖

// 替换全局字体使用

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

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

替换字体01.jpg

xmlns:app="/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" />

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。