Use fonts from the support library in Leanback

In the Android 26 support library, you can use fonts in styles and widgets. Then you need to use AppCompatActivityand use styles that extend from Theme.AppCompat.

I would like to use custom fonts in Android TV (using the support library), but then I can not use the style Theme.Leanback.

Can I use a Theme.Leanbackfont style ?

+4
source share
1 answer

I ended up using Calligraphy

build.gradle:

implementation 'uk.co.chrisjenx:calligraphy:2.3.0'

An example of applying the font assets/font/fancyfont.otfto the operation `GuidedStepFragment:

LoginActivity.kt:

class LoginActivity : Activity() {

    override fun attachBaseContext(newBase: Context?) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase))
    }
}

styles.xml:

<style name="LoginActivityTheme" parent="@style/Theme.Leanback.GuidedStep">
    <item name="guidanceTitleStyle">@style/Login.TitleStyle</item>
</style>

<style name="Login.TitleStyle" parent="Widget.Leanback.GuidanceTitleStyle">
    <item name="fontPath">font/fancy_font.otf</item>
</style>

AndroidManifest.xml:

    <activity android:name=".LoginActivity"
        android:theme="@style/LoginActivityTheme"/>
0

Source: https://habr.com/ru/post/1686966/


All Articles