Category / Section
How to prevent system font-size changing effects to android application in Xamarin.Forms
7 mins read
This article explains how to restrict the system font size changes effects to SfAutoComplete control in Xamarin.Forms Android platform as shown in the following code screenshot.
[XAML]
Let’s have a SfAutoComplete control with FontSize of 20.
<StackLayout Margin="0,50,10,10"> <autocomplete:SfAutoComplete HeightRequest="60" Text="Font-20" TextSize="20"/> </StackLayout>
[C#]
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. So CreateConfigurationContext is used for APl level greater than 25.
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { public override Resources Resources { Resources resource = base.Resources; Configuration configuration = new Configuration(); configuration.SetToDefaults(); if (Build.VERSION.SdkInt >= Build.VERSION_CODES.NMr1) { return CreateConfigurationContext(configuration).Resources; } else { resource.UpdateConfiguration(configuration, resource.DisplayMetrics); return resource; } } … }
Output
Before applying the changes
SfAutoComplete with font size of 20 | Change the system font size | SfAutoComplete looks with huge font size |
After applying the changes
See Also,