I don't want the 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 (i.e. too big).
How can I solve it?
I'm writing my code in C#, Xamarin.Forms project.
I don't want the 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 (i.e. too big).
How can I solve it?
I'm 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();
...
}
code works but it dont't work with horizontal page
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();
...
}
© 2022 - 2024 — McMap. All rights reserved.
FontSize
attribute to the desired control? – Kleinsp
then. – Odawa