James Lavery
James Lavery

Reputation: 949

Xamarin.Forms android - adjusting control sizes to account for accessibility settings

On Android, it's possible for the user to set a larger font for accessibility reasons.

Discussions like this one go into some details on how/whether the named or fixed (number) sizes are affected by accessibility settings.

I have a slightly different question. Is there a way to adjust the size of controls to account for font size? With our app, if the user sets a large font size under Accessibility, then the text in buttons, Infragistics DataGrids, ListViews etc. don't fit into their controls. Am I missing something?

Upvotes: 3

Views: 1056

Answers (1)

York Shen
York Shen

Reputation: 9084

it's possible for the user to set a larger font for accessibility reasons.

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

Discussions like this one go into some details on how/whether the named or fixed (number) sizes are affected by accessibility settings.

I don't really understand what you mean, if you need set a fixed text size for your application, you could refer to:

how to prevent system font-size changing effects to android application?

Upvotes: 3

Related Questions