2

I have a Button, using like this <android.widget.Button, because of needs to set up custom background (read more about issue with DayNight theme and Buttons). Next I need set custom font, see my style below. In Studio designer panel custom font looks good, but running on device there is Roboto (default) font instead of my custom font (Nunito). Any suggestions? AS4.1.2/API30

<style name="ButtonGetStarted" parent="Widget.MaterialComponents.Button">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">60dp</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:textSize">24sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">@color/text_invert</item>
    <item name="android:fontFamily">@font/app_font</item>
    <item name="android:background">@drawable/button_selector_get_started</item>
</style>

app_font.xml:

<font-family xmlns:app="http://schemas.android.com/apk/res-auto">    
    <font
        app:fontStyle="normal"
        app:font="@font/nunito_regular" />

    <font
        app:fontStyle="italic"
        app:font="@font/nunito_regular_italic" />

</font-family>
Konstantin Konopko
  • 5,229
  • 4
  • 36
  • 62

1 Answers1

0

Create a TextAppearance here example

 <style name="TextAppearance.Robin.Button" parent="TextAppearance.MaterialComponents.Button">
            <item name="fontFamily">@font/dosis_medium</item>
                <item name="android:fontFamily">@font/dosis_medium</item>
                <item name="android:textSize">15sp</item> 
</style>

Now Set the TextAppearance in Your Button Style

<style name="ButtonGetStarted" parent="Widget.MaterialComponents.Button">
 <item name="android:textAppearance">@style/TextAppearance.Robin.Button</item>
   .
   .
   .
   .
</style>

here reference to the MDC guide

Also you can use button itself

<Button
android:textAppearance:"android:textAppearance="@style/yourstYle
/>
Morpheus
  • 550
  • 1
  • 9
  • 23