I want to set a ChipDrawable with a custom font on my EditText. But the font is applied only when I focus the EditText. And the text is cropped...
styles.xml
<style name="AppTheme.ChipDrawable.Text" parent="TextAppearance.MaterialComponents.Chip">
<item name="android:fontFamily">@font/my_font</item>
</style>
MyActivity
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
I encounter this issue in 1.2.1 and 1.3.0-alpha03
Thanks in advance for your help
I found a way to fix it but I think it's not the most efficient because we load the font synchronously.