Search code examples
androidfonts

Using font in XML in API < 26


https://developer.android.com/preview/features/working-with-fonts.html

Android API 26 supports this but do we have a support library that can provide use of fonts as a resource in res? [ font in XML ] If yes, up-to what API is it supported?

I am talking about the Android O SDK feature which allows us to set font in XML as given in the link above. This is not a native feature in MM I m sure.


Solution

  • According to Google it is supported on Android 4.0+ (API 14+) as long as these conditions are met:

    • You are using the support library version 26.0.0-beta1 or later
    • You are using AppCompat

    Sources:

    Fonts in XML - Using the support library

    Support Library revision history

    I was hoping I could use this in app widgets on Android versions earlier than 8 (API 26), however it's not possible, as AppCompatTextView cannot be used in app widgets. None of the third party alternatives to Android O's 'Fonts in XML' such as the Caligraphy library work in app widgets either.

    The only alternative for app widgets is using an ImageView instead of a TextView and using RemoteViews methods such as setImageViewUri(...) and setImageViewBitmap(...), both of which are problematic.