簡體   English   中英

在我的應用中禁用系統字體大小效果

[英]Disable system font size effect in my app

我不希望系統字體大小對我的應用程序產生任何影響。 如果我在 Android 設置中增加系統字體大小,我的應用程序中的文本將不可讀(即太大)。

我該如何解決?

我正在用 C#、Xamarin.Forms 項目編寫我的代碼。

在我的應用程序中禁用系統字體大小效果

如果您需要為您的應用程序設置固定的文本大小,您可以嘗試使用以下代碼來實現此功能:

private void initFontScale()
{
     Configuration configuration = Resources.Configuration;
     configuration.FontScale = (float)1.45;
     //0.85 small, 1 standard, 1.15 big,1.3 more bigger ,1.45 supper big 
     DisplayMetrics metrics = new DisplayMetrics();
     WindowManager.DefaultDisplay.GetMetrics(metrics);
     metrics.ScaledDensity = configuration.FontScale * metrics.Density;
     BaseContext.Resources.UpdateConfiguration(configuration, metrics);
}

protected override void OnCreate(Bundle bundle)
{
    initFontScale();
    ...
}

代碼有效,但不適用於水平頁面

private void initFontScale()
{
     Configuration configuration = Resources.Configuration;
     configuration.FontScale = (float)1.45;
     //0.85 small, 1 standard, 1.15 big,1.3 more bigger ,1.45 supper big 
     DisplayMetrics metrics = new DisplayMetrics();
     WindowManager.DefaultDisplay.GetMetrics(metrics);
     metrics.ScaledDensity = configuration.FontScale * metrics.Density;
     BaseContext.Resources.UpdateConfiguration(configuration, metrics);
}

protected override void OnCreate(Bundle bundle)
{
    initFontScale();
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM