Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable system font size effect in my app

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.

like image 433
Arrow Avatar asked May 11 '18 09:05

Arrow


People also ask

Can I prevent my application from changing system font-szie?

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!

How to prevent app layout issue when font size is changed?

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);

Is it possible to disable fontscale in the whole app?

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.

How to restrict the font size of sfautocomplete control in Android?

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.


2 Answers

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();
    ...
}
like image 81
York Shen Avatar answered Sep 20 '22 17:09

York Shen


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();
    ...
}
like image 38
Minh Seven Avatar answered Sep 20 '22 17:09

Minh Seven