Toast throws ArrayIndexOutOfBoundsException with appcompat v26 when using fontFamily attribute in theme

前端 未结 2 1701
一生所求
一生所求 2021-01-06 13:35

Whenever I show a Toast, the app crashes.

The app works fine if I use older version of AppCompat library or remove fontFamily from the styl

相关标签:
2条回答
  • 2021-01-06 13:57

    According to the Android Developer Guide for fonts in xml

    Adding fonts to style

    Open the styles.xml, and set the fontFamily attribute to the font file you want to access.

    <style name="customfontstyle" parent="@android:style/TextAppearance.Small">
        <item name="android:fontFamily">@font/lobster</item> 
    </style>
    

    In your case you should put the @font/ prefix

    <item name="android:fontFamily">@font/sans-serif-light</item>
    
    0 讨论(0)
  • 2021-01-06 14:05

    Add font in Theme like below-

        <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
            <item name="android:textViewStyle">@style/TextViewStyle</item>
            <item name="android:buttonStyle">@style/ButtonStyle</item>
        </style>
    
        <style name="TextViewStyle" parent="android:Widget.TextView">
            <item name="android:fontFamily">sans-serif-light</item>
        </style>
    
        <style name="ButtonStyle" parent="Widget.AppCompat.Button">
            <item name="android:fontFamily">sans-serif-light</item>
        </style>
    
    0 讨论(0)
提交回复
热议问题