【问题标题】:Use fonts from support library in Leanback在 Leanback 中使用支持库中的字体
【发布时间】:2018-03-17 03:58:48
【问题描述】:

从 android 支持库 26 开始,可以在样式和小部件中使用 fonts。然后,您必须使用 AppCompatActivity 并使用从 Theme.AppCompat 扩展而来的样式。

我想在 Android TV 中使用自定义字体(使用支持库),但我无法使用 Theme.Leanback 样式。

有没有办法在字体支持下使用Theme.Leanback 样式?

【问题讨论】:

  • 不,它不是那个的副本。我知道如何使用字体(以及许多替代品,如自定义小部件、书法、数据绑定、以编程方式等)。我的问题不是关于使用一般字体,而是针对支持库和leanback 主题。

标签: android-support-library android-tv


【解决方案1】:

我最终使用了Calligraphy

build.gradle:

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

assets/font/fancyfont.otf 中的字体应用到`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"/>

【讨论】:

    猜你喜欢
    • 2016-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多