android - 应用程序文本大小不随系统字体大小缩放

标签 android fonts sp scale-independent

我必须处理现有的 Android 应用程序,其中所有文本都在布局 XML 文件的 SP 单元中提及。

但是,应用程序的文字大小并没有随系统字体一起调整。即,如果我从 Settings -> Accessibility -> Font Size 更改系统字体大小,应用程序的字体大小根本不会改变。

PFB 从我的布局文件中摘录,SP 中提到了 TextView 的 textSize

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="12dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:gravity="center"
        android:text="@string/find_an_noffice"
        android:textSize="12sp"/>
</LinearLayout>

我认为问题与布局结构无关,因此我在示例应用程序中使用了相同的布局文件。此示例应用程序按预期工作。即,应用程序的字体大小会根据系统字体进行调整。

我的原始应用程序与示例应用程序不同的可能性有哪些?

如有任何帮助,我们将不胜感激。

最佳答案

我已经找到了问题的根本原因。我的应用正在创建一个新的 Configuration,这导致了这个问题。

导致这个问题的代码:

Locale locale = new Locale(isSpanish() ? "es" : "en");
Locale.setDefault(locale);

Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());

如果我将行 Configuration config = new Configuration(); 更改为 Configuration config = context.getResources().getConfiguration(); 应用程序字体将根据系统字体大小的变化。

希望这对某人有帮助。

关于android - 应用程序文本大小不随系统字体大小缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43763993/

相关文章:

ios - 如何在 Objective-c 中使用 "private use area"字体

r - 用多边形子集空间点

r - 通过使用并行处理和/或 plyr/dplyr 提高 gDistance 函数的速度/使用?

Android 应用程序始终保持横向

android - 如何在不使用 orderBy 两次的情况下构建查询来检索有序列表?

android - 使用 TabHost 时出现错误

android - 可以使用两个 ArrayLists 来填充一个带有自定义布局的微调器吗?

css - 如何修复 Internet Explorer 9 和 10 忽略@font-face 和字体系列?

java - Java 中的字符串长度(以像素为单位)

r - 使用 spplot 的德国热图