I would like to change the typeface of Chip view from design support library. After I explorer it's source code, I found that it draw the text in ChipDrawable directly by Paint and I can't find any public method to change the typeface. How should I try to change that Chip view typeface? Please help. Thanks you.
It's a little late but I will post my solution in case someone is still interested.
First create a font family xml with your custom font.
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font app:fontStyle="normal" app:fontWeight="400" app:font="@font/my_custom_font"/>
</font-family>
Then add a chip style to your styles xml that uses your font family:
<style name="chipText" parent="TextAppearance.MaterialComponents.Chip">
<item name="android:textSize">14sp</item>
<item name="android:fontFamily">@font/my_font_family</item>
</style>
Then, when you create your chip view in xml, set the textAppearance attribute:
android:textAppearance="@style/chipText"
your solution working normal chip view - it still has some issue chip inside TextInputLayout. (font not changing)
notes: after screen rotates custom font changed, I don't know why
implementation "com.google.android.material:material:1.3.0-alpha01"
<com.google.android.material.textfield.TextInputLayout
android:layout_width="240dp"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_gravity="center"
android:textAppearance="@style/chipText"
android:hint="Text Field">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Text"
android:textAppearance="@style/chipText"/>
</com.google.android.material.textfield.TextInputLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With