android-support-library - 在 Leanback 中使用支持库中的字体

标签 android-support-library android-tv

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

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

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

最佳答案

我最终使用了 Calligraphy

构建.gradle:
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
assets/font/fancyfont.otf 中应用字体的示例它到一个`GuidedStepFragment 事件:

登录事件.kt:

class LoginActivity : Activity() {

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

样式.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"/>

关于android-support-library - 在 Leanback 中使用支持库中的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46587200/

相关文章:

Android Studio 奇怪的警告

android - 可以在 Android TV 应用程序中嵌入电视信号吗?

android - XML 中的字体 android :fontFamily is not applied to toolbars

android - Material 按钮上的圆角

Android 支持库 ActionBar 在 2.3 设备中不起作用

android - 使用 RowsFragment 时,ObjectAdapter.setPresenterSelector 有什么作用吗?

chromecast - 使用 Google Cast 转换到 Android TV 时,是否可以捕捉到 Android TV 的 Remote 按钮?

android - 如何让应用程序为 Android TV 使用不同的横幅?

android - ViewPager 类似于 AndroidTV 中 BrowseFragment 中的东西

android - 有没有办法在样式文件中设置新的 Android 支持 AutoSize Textview?