Skip to content

This demo sample explains us to find the way of preventing the system font size changes effects to android application in Xamarin

Notifications You must be signed in to change notification settings

SyncfusionExamples/Prevent-system-font-size-changing-effects-to-android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Prevent-system-font-size-changing-effects-to-android

This article explains how to restrict the system font size changes effects to SfAutoComplete control in Xamarin.Forms Android platform Refer KB for more as per in below code snippet

[XAML]

Let’s have an 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 to default to restrict the font size effect on 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

Entry with font size of 20

Change the system font size

Change the system font size

Entry looks with huge font size

Entry looks with huge font size

After applying the changes, it keeps in same

Desired output

About

This demo sample explains us to find the way of preventing the system font size changes effects to android application in Xamarin

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages