Prevent change font size

Laura83Laura83 USMember ✭✭

Hi guys. Is there a way to prevent user changes the fontsize?
I need the exact fontsize for label, button, listview and so on...
Any help? Thanks!

Posts

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Just my perspective as a user: It's my device; I'll decide what size font I need in order for my 50 year old eyes to be able to read it. That's why there is a system-wide setting for this. When I choose to make the font larger than usual I accept that less data will be available on screen and that I'll have to scroll.

    My perspective as a developer: Accept that the user owns the device, not me. They may change the theme, fonts, orientation, 3rd party theme tools, 3rd party font changers etc. Test the app through the range of default controls panels from small to large, dark and light. I'm responsible for it working through the expected operating conditions.

  • Laura83Laura83 USMember ✭✭

    Ok. Thank you for your opinion. But you don't have answered my question XD

  • JTOneJTOne USMember ✭✭

    hat's how you do it in 2018 (Xamarin.Android/C# - same approach in other languages):

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
    protected override void OnCreate(Bundle bundle)
    {
    ...
    }

    protected override void AttachBaseContext(Context @base)
    {
        var configuration = new Configuration(@base.Resources.Configuration);
    
        configuration.FontScale = 1f;
        var config =  Application.Context.CreateConfigurationContext(configuration);
    
        base.AttachBaseContext(config);
    }
    

    }
    All you need is override attachBaseContext method of activity and update config there.

    getBaseContext().getResources().updateConfiguration() is deprecated though there're numerous examples with this method. If you use this approach besides the IDE warning you might find some parts of your app not scaled.

Sign In or Register to comment.