繁体   English   中英

xml中的android字体 - 如何覆盖书法库中的默认字体

[英]android fonts in xml - how to override default font like calligraphy library does

我试图在xml中换掉书法 (非常有用的库)for android 字体,但我不知道如何更改所有视图的默认字体,如书法。 书法能够在初始化时更改默认字体。 我怎么能用android字体支持库呢?

从android开发者网站上的xml文章中的字体我看到我们可以将字体系列应用到这样的一个视图:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@font/lobster"/>

但如果我想改变整个应用程序的字体怎么办?

我想使用android xml字体的原因是由于这个错误,但这与问题无关。

使用Support Library 26.1.0,我通过设置应用程序主题的android:fontFamily属性,设法为整个应用程序设置了默认字体:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
     ...
    <item name="android:fontFamily">@font/proxima_nova</item>
</style>

proxima_nova.xml是一个字体资源文件:

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="UnusedAttribute">
    <!-- As of Android Support Library 26.0, we must declare both sets of attributes to ensure
         our fonts load on devices running Android 8.0 (API level 26) or lower. -->
    <font
        android:font="@font/proxima_nova_light"
        android:fontStyle="normal"
        android:fontWeight="300"
        app:font="@font/proxima_nova_light"
        app:fontStyle="normal"
        app:fontWeight="300" />
    <font
        android:font="@font/proxima_nova_semibold"
        android:fontWeight="600"
        app:font="@font/proxima_nova_semibold"
        app:fontWeight="600" />
</font-family>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM