在我的应用程序中禁用系统字体大小效果. -C#-Xamarin.Forms Android [英] Disable system font size effect in my App. - C# - Xamarin.Forms Android

查看:138
本文介绍了在我的应用程序中禁用系统字体大小效果. -C#-Xamarin.Forms Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望系统字体大小对我的应用程序有任何影响.如果我在android设置中增加系统字体大小,则我的应用程序中的文本将不可读. (太大.)我该怎么解决?

I dont want to that system font size have any effect in my app. If i increase system font size in android settings, the text in my app will be unreadable. (Too big.) How can i solve it?

PS:我正在用Xamarin.Forms项目的C#语言编写代码.

PS: Im writing my code in C#, Xamarin.Forms project.

谢谢

推荐答案

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

Disable system font size effect in my App

如果需要为应用程序设置固定的文本大小,请尝试使用以下代码来实现此功能:

If you need set a fixed text size for your application, you try using the following code to implement this feature:

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

这篇关于在我的应用程序中禁用系统字体大小效果. -C#-Xamarin.Forms Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆