Android 应用程序文本大小不随系统字体大小缩放
我必须在现有的Android应用程序上工作,其中所有文本都在布局XML文件的SP单元中提到 但是,应用程序的文本大小不会随系统字体一起调整。也就是说,如果我从Android 应用程序文本大小不随系统字体大小缩放,android,fonts,sp,scale-independent,Android,Fonts,Sp,Scale Independent,我必须在现有的Android应用程序上工作,其中所有文本都在布局XML文件的SP单元中提到 但是,应用程序的文本大小不会随系统字体一起调整。也就是说,如果我从设置->辅助功能->字体大小更改系统字体大小,则应用程序的字体大小根本不会更改 PFB从我的布局文件中摘录,SP中提到了TextView的textSize <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content"
设置->辅助功能->字体大小
更改系统字体大小,则应用程序的字体大小根本不会更改
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>
我认为这个问题与布局结构无关,因此我在示例应用程序中使用了相同的布局文件。此示例应用程序按预期工作。即,应用程序的字体大小根据系统字体进行调整
我的原始应用程序不作为示例应用程序的可能性是什么
任何帮助都将不胜感激。我已找到问题的根本原因。我的应用程序正在创建新的配置
,这导致了问题
导致此问题的代码:
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()
toConfiguration config=context.getResources().getConfiguration()代码>应用程序字体将根据系统字体大小的变化进行缩放
希望这可能会对某些人有所帮助。所以,要明确的是:相同的布局在应用程序A中有效,但在应用程序B中无效?如果是这样,这两个应用程序有什么不同?例如,他们的主题不同吗?@commonware:谢谢你的评论。是的,相同的布局在AppA中工作,而不是在AppB中。它们都使用相同的主题theme.AppCompat.Light.NoActionBar
。这也是让我困惑的地方。字体不可缩放还有其他可能性吗?我想不起来了。@commonware我找到了解决方案。请看一看。