Chipdrawable 自定义字体文本裁剪

Chipdrawable custom font text cropped

我想在我的 EditText 上设置一个带有自定义字体的 ChipDrawable。但是只有当我关注 EditText 时才会应用字体。并且文本被裁剪...

聚焦前:

聚焦编辑文本后

styles.xml

    <style name="AppTheme.ChipDrawable.Text" parent="TextAppearance.MaterialComponents.Chip">
        <item name="android:fontFamily">@font/my_font</item>
    </style>

我的活动

        val text = "My text"
        val stringBuilder = SpannableStringBuilder(text)
        val chipDrawable = ChipDrawable.createFromResource(this, R.xml.chips_standalone)
        chipDrawable.text = text
        chipDrawable.setBounds(0, 0, chipDrawable.intrinsicWidth, chipDrawable.intrinsicHeight)
        //chipDrawable.setTextAppearanceResource(R.style.AppTheme_ChipDrawable_Text) // not works programmatically either
        val span = ImageSpan(chipDrawable)
        stringBuilder.setSpan(span, 0, text.length, 0)
        editText.text = stringBuilder

chip_standalone.xml

<chip xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:textAppearance="@style/AppTheme.ChipDrawable.Text" /> // Not works either in xml

我在 1.2.1 和 1.3.0-alpha03 中遇到这个问题

在此先感谢您的帮助

我找到了修复它的方法,但我认为它不是最有效的,因为我们是同步加载字体的。

TextAppearanceConfig.setShouldLoadFontSynchronously(true)
chipDrawable.setTextAppearanceResource(R.style.AppTheme_ChipDrawable_Text)
TextAppearanceConfig.setShouldLoadFontSynchronously(false)
chipDrawable.setBounds(0, 0, chipDrawable.intrinsicWidth, chipDrawable.intrinsicHeight)