6

From android support library 26 onwards, it is possible to use fonts in styles and widgets. You then have to use AppCompatActivity and use styles extending from Theme.AppCompat.

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

Is there a way of using the Theme.Leanback style with the font support?

OKA
  • 1,453
  • 2
  • 11
  • 7
  • possible duplicate of https://stackoverflow.com/questions/2711858/is-it-possible-to-set-a-custom-font-for-entire-of-application – ReyAnthonyRenacia Oct 06 '17 at 19:00
  • No, it is not a duplicate of that. I know how to use fonts (and the many alternatives like custom widgets, calligraphy, databinding, programmatically, etc). My question is not about using fonts in general, but specific to the support libarary and the leanback theme. – OKA Oct 07 '17 at 01:11

1 Answers1

0

I ended up using Calligraphy

build.gradle:

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

Example of applying a font in assets/font/fancyfont.otf it to a `GuidedStepFragment activity:

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"/>
Xiao
  • 1,552
  • 2
  • 22
  • 20