Xamarin 禁止系统字体调节

最近开发基于Xamarin安卓的一个App, 发现在不同的手机上设置的显示效果不统一, 由于部分机型开启了"老人" 模式, 字体显示特别大, 会间接影响到软件的显示布局, 导致观感不太好。

所以, 通过了解, 可以进行修改底层的资源配置, 让系统修改字体对软件本身的字体不产生任何影响。

查看到了一些资料, 关于以下一段代码, 可以设置系统字体影响, 但是由于该版本在 Version2.5 已经是被弃用的方法,尽管有用, 所以还是需要找到最新的配置方式。

最后查阅资料, 我们只需要重写一个 AttachBaseContext 方法, 把其中的Context覆盖即可, 方法如下。

        protected override void AttachBaseContext(Context @base)
        {
            Configuration config = new Configuration();
            config = @base.Resources.Configuration;
            config.FontScale = 1.00f;
            Context context = @base.CreateConfigurationContext(config);
            base.AttachBaseContext(context);
        }

MainActivity 下的完整代码如下(红色为重写的代码部分):

猜你喜欢

转载自www.cnblogs.com/zh7791/p/12522651.html