sun*_*nil 4 fonts android r-sp scale-independent
我不得不在现有的 Android 应用程序上工作,其中所有文本都在布局 XML 文件中的 SP 单元中提及。
但是,应用程序的文本大小不会随系统字体一起调整。即,如果我从 更改系统字体大小Settings -> Accessibility -> Font Size,应用程序的字体大小根本不会改变。
PFB 摘自我的布局文件,其中TextView's textSize在 SP 中提到。
<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>
Run Code Online (Sandbox Code Playgroud)
我认为问题与布局结构无关,因此我在示例应用程序中使用了相同的布局文件。此示例应用程序按预期工作。即,应用程序的字体大小与系统字体一起调整。
我的原始应用程序不作为示例应用程序运行的可能性有哪些?
任何帮助,将不胜感激。
我已经找到了问题的根本原因。我的应用程序正在创建一个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());
Run Code Online (Sandbox Code Playgroud)
如果我改线Configuration config = new Configuration();到Configuration config = context.getResources().getConfiguration();应用程序的字体将根据系统字体大小的变化规模。
希望这可以帮助某人。
| 归档时间: |
|
| 查看次数: |
1234 次 |
| 最近记录: |