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.
But in IOS it restricted to specific applications like calendar, mails, ect by the System. For Android, there is not restriction. So can i prevent my application from changing system font-szie. You cannot stop the user from changing the system font size; you'll just have to use dp and ignore the lint errors!
There's another way to prevent app layout issue / font issue from the setting font size change. You can try // ignore the font scale here final Configuration newConfiguration = new Configuration ( newBase.getResources ().getConfiguration () ); newConfiguration.fontScale = 1.0f; applyOverrideConfiguration (newConfiguration);
Tried answers about disabling fontScale in whole application. It's working, but I come to answer it's a terrible idea for only one reason: You don't make your app better for visually impaired people. Better way (I think) it's allow font scale but with restrictions only in some places, where you can't scale your text for it looks readable.
Let’s have a SfAutoComplete control with FontSize of 20. In the Xamarin.Forms Android MainActivity.cs, override the Resources and set the configuration as default to restrict the font size effect on the application. Resources.UpdateConfiguration () has been deprecated in API 25.
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();
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With