我目前面临一个问题 - 第三次 -.-。我们正在使用 xamarin 开发一个应用程序。到目前为止,一切都很好。但在 Android 上有一个小问题。由于三星决定必须销售“折叠”智能手机,我们的客户遇到了一个小问题。我不知道这是否只是因为他不再是最小的,或者是因为智能手机的原因。最后没关系。。
如果系统字体大小发生变化,我们的 Android 应用程序也会更改字体大小。这会导致整个应用程序出现 UI 错误。当然,我们可以应用完整的应用程序来提高响应速度。但说实话,我们的目标群体是在15岁到25岁之间。所以在99.9%的时间里,用户并没有改变系统字体大小。
我已经在互联网上找到/找到了解决方案。
所以我将其添加到我的MainActivity.cs在我的 Android 项目中。
public override Android.Content.Res.Resources Resources
{
get
{
//Prevent system font size from affecting in -app font size
Android.Content.Res.Configuration config = base.Resources.Configuration;
if (config == null)
config = new Android.Content.Res.Configuration();
config.FontScale = 1f;
return CreateConfigurationContext(config).Resources;
}
}
直到今天它工作正常,但后来我将模拟器更新到 Android 12,我遇到了此代码的新问题。当我想在应用程序中播放视频或打开图像时,应用程序崩溃并出现 NullPointerException。如果我删除这段代码,系统字体大小将不再被忽略。
有没有人遇到过类似的问题并且可能已经找到了解决方案?
所以我将其添加到我的MainActivity.cs在我的 Android 项目中。
public override Android.Content.Res.Resources Resources
{
get
{
//Prevent system font size from affecting in -app font size
Android.Content.Res.Configuration config = base.Resources.Configuration;
if (config == null)
config = new Android.Content.Res.Configuration();
config.FontScale = 1f;
return CreateConfigurationContext(config).Resources;
}
}
在 Android 11 之前,它运行得很好。但自 Android 12 以来,我无法在我们的应用程序中播放视频或打开图像。