Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove monospace font from button on material components

How I can remove the monospace font from my buttons using the new material components?

<com.google.android.material.button.MaterialButton
        android:id="@+id/btn_register"
        style="@style/Widget.MaterialComponents.Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        app:fontFamily="@font/lato"
        app:backgroundTint="@color/white"
        android:textColor="?colorPrimary"
        android:text="Open Register Screen" />

This image shows the difference I'm looking to eliminate:

like image 793
Fillipe Duoli Avatar asked Jul 23 '18 14:07

Fillipe Duoli


Video Answer


2 Answers

I found the problem. It is not monospace font, it is letterSpacing. So I just add android:letterSpacing="0" on button to solve.

like image 52
Fillipe Duoli Avatar answered Oct 22 '22 13:10

Fillipe Duoli


To update letterspacing globally for all your Buttons, you should use theming: https://material.io/develop/android/theming/typography/

You can redefine ?attr/textAppearanceButton in your theme to point to a different text appearance that has whatever letterSpacing you want.

Define the attr in your theme like this:

<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
    <item name="textAppearanceButton">@style/TextAppearance.MyApp.Button</item>
</style>

And create a new TextAppearance Style:

<style name="TextAppearance.MyApp.Button" parent="TextAppearance.MaterialComponents.Button">
  <item name="android:letterSpacing">0</item>
</style>
like image 20
Cameron Ketcham Avatar answered Oct 22 '22 13:10

Cameron Ketcham