Disable system font size effect in my App. - C# - Xamarin.Forms Android

一个人想着一个人 提交于 2020-05-14 01:22:29

问题


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: Im writing my code in C#, Xamarin.Forms project.

Thanks


回答1:


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


来源:https://stackoverflow.com/questions/50289763/disable-system-font-size-effect-in-my-app-c-sharp-xamarin-forms-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!