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

Application text size not scaling with system font size

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

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

PFB 摘自我的布局文件,SP 中提到了 TextView's 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();,应用程序字体将根据系统字体大小的变化进行缩放。

希望这对某人有所帮助。