4

我正在尝试将 TextAppearanceSpan 设置为 SpannableStringBuilder。它适用于 API 27 及更高版本,但我找不到 api 26 及更低版本的解决方案。这是我正在使用的代码:

fun getMenuSpannable(context: Context, title: String): SpannableStringBuilder {
    return SpannableStringBuilder(title).apply {
        setSpan(TextAppearanceSpan(context, R.style.TextAppearance_Theme_Subtitle1), 0, title.length, 0)
    }
}

<style name="TextAppearance.Theme.Subtitle1" parent="TextAppearance.MaterialComponents.Subtitle1">
    <item name="typeface">MacanRegular</item>
    <item name="fontFamily">@font/macan_regular</item>
    <item name="android:fontFamily">@font/macan_regular</item>
    <item name="android:textSize">16sp</item>
    <item name="lineSpacingMultiplier">1.4</item>
    <item name="android:letterSpacing">-0.04</item>
</style>
4

0 回答 0