【问题标题】:Font resources for different Languages不同语言的字体资源
【发布时间】:2019-02-01 03:15:13
【问题描述】:

我正在尝试使用字体资源目录并在 xml 文件中使用不同的字体,以便优先使用它们。我读了这个thread,但我无法解决问题。我正在使用支持库 v27,我知道它支持 res 中的字体而不是资产文件夹。每当我更改应用程序的语言时,它只使用位于 font-fa-rIR 文件夹中的字体。我希望应用程序分别为不同类型的语言使用不同的字体。我从应用程序的 res 目录中附加了一张图片。我的问题在哪里?我该如何解决?提前致谢。

preference_button.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dp">

    <TextView
        android:id="@android:id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/font_1" />

    <TextView
        android:id="@+id/summary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/font_1" />

</LinearLayout>

【问题讨论】:

    标签: android locale android-resources android-fonts


    【解决方案1】:

    也许这阙能帮到你

    参考:Chnaging Locale It self

    Locale locale2 = new Locale("fr"); 
    Locale.setDefault(locale2);
    Configuration config2 = new Configuration();
    config2.locale = locale2;
    getBaseContext().getResources().updateConfiguration(
        config2, getBaseContext().getResources().getDisplayMetrics());
    

    Res 中的字体

    TextView tv_the = (TextView) findViewById(R.id.the);
    Typeface face = Typeface.createFromAsset(getAssets(), "font.ttf");
    tv_the.setTypeface(face);
    

    欲了解更多信息:How to set custom font in .xml file instead of .java file?

    【讨论】:

    • 谢谢,但我有一个类即使在运行时也可以更改语言环境。我很困惑如何在 res 中使用与布局和其他资源相同的字体。
    • 谢谢,在偏好 xml 文件中使用修改后的 TextView 是个好主意。在这种情况下,我不需要使用字体资源目录。感谢海洋
    • @Ashvinsolanki 更改语言环境本身没有获取“font-fr”文件夹中可用的字体。在应用程序重新启动时,它正在使用该字体,但不是在运行时。如何做到这一点
    • @user137021 这可能会帮助你stackoverflow.com/questions/40221711/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    相关资源
    最近更新 更多