我目前面臨一個問題-第三次-.-。我們正在使用 xamarin 開發一個應用程式。到目前為止,一切都很好。但是在Android上存在一個小問題。由于三星決定必須銷售“折疊”智能手機,我們的客戶遇到了一個小問題。我不知道這僅僅是因為他不再是最年輕的,還是因為智能手機。最后沒關系。。
停止跳動.. 如果系統字體大小發生變化,我們的 Android 應用程式會更改字體大小。這會導致整個應用程式出現 UI 錯誤。當然,我們可以應用我們完整的應用程式來提高回應速度。但老實說,我們的目標群體在 15 到 25 之間。所以在 99.9% 的時間里,用戶沒有改變系統字體大小。
我已經在互聯網上找到/找到了解決方案。
所以我將它添加到我的 Android 專案中的MainActivity.cs中。
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。如果我洗掉此代碼,系統字體大小將不再被忽略。
有沒有人遇到過類似的問題,也許已經找到了解決方案?
所以我將它添加到我的 Android 專案中的MainActivity.cs中。
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 以來,我無法在我們的應用中播放視頻或打開影像。
uj5u.com熱心網友回復:
您可以嘗試將以下代碼放入 MainActivity 以防止 android 系統字體大小影回應用內字體大小。
protected override void AttachBaseContext(Context @base)
{
Configuration configuration = new Configuration(@base.Resources.Configuration);
configuration.FontScale = 1.0f;
ApplyOverrideConfiguration(configuration);
base.AttachBaseContext(@base);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/530273.html
標籤:安卓xamarinxamarin.android安卓12
