簡體   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