xamarin 在我的应用中禁用系统字体大小效果

disbfnqx  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(159)

我不希望系统字体大小对我的应用程序有任何影响。如果我在Android设置中增加系统字体大小,我的应用程序中的文本将无法阅读(即太大)。
我该怎么解决呢?
我正在用C#编写Xamarin.Forms项目的代码。

pgpifvop

pgpifvop1#

代码工作,但它不工作与水平页面

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();
    ...
}
tcomlyy6

tcomlyy62#

在我的应用程序中禁用系统字体大小效果
如果需要为应用程序设置固定的文本大小,请尝试使用以下代码实现此功能:

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();
    ...
}

相关问题