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

James Lavery Source

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?

androidxamarin.formsaccessibility

Answers

answered 4 days ago York Shen - MSFT #1

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?

comments powered by Disqus