Disable system font size effect in my app
Asked Answered
F

2

10

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.

Fictile answered 11/5, 2018 at 9:58 Comment(5)
Did you tried to add the FontSize attribute to the desired control?Klein
Yeah i did..... :)Fictile
there is no accepted answer but it may could help you: #43291257Klein
I already did it but unfortunately nothing changed. :(Fictile
Don't use sp then.Odawa
K
20

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();
    ...
}
Krona answered 14/5, 2018 at 1:54 Comment(3)
to avoid the use of the Obsolete method UpdateConfiguration, use this: BaseContext.ApplicationContext.CreateConfigurationContext(configuration); BaseContext.Resources.DisplayMetrics.SetTo(metrics);Tanguy
This only works with the non depreciated methods as stated in the comment!Gunstock
This works with Api 31, but not anymore with Api 32.Landside
O
1

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();
    ...
}
Oospore answered 12/8, 2020 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.