Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] Make named font size scaled for accessibility, and all numerical font sizes fixed #13543

Open
abbalooga opened this issue Jan 26, 2021 · 6 comments

Comments

@abbalooga
Copy link

Summary

I cannot find a way to keep font sizes fixed on android between devices using differing font scale settings. This makes it impossible to create a neat interface for displaying information that is fixed across devices.
It would make logic that named font sizes are subject to user scaling but numbered font sizes are fixed to the developers design wishes.

API Changes

We would require an ability to set font scaling in mainactivity.cs

Intended Use Case

For users of Xamarin who desire to not have font wrapping out of view when users have system font scaling set above 1.

@Tommigun1980
Copy link

This is especially important with font images.

@abbalooga
Copy link
Author

A solution to this problem for APN28 and above couldn't be found. Any working work around would be appreciated.

@Tommigun1980
Copy link

Tommigun1980 commented Jan 28, 2021

Fwiw I am currently sprucing up my UI to work better with accessibility font scaling and am running into this exact problem quite hard.

There really needs to be some way to tell Xamarin not to scale a specific label/whatever, for example when font icons are used. Expected would be for the app's text to become larger but not icons, and there really doesn't seem to exist any way to control this atm.

I am not 100% certain if it would be enough for Xamarin to scale named sizes and not apply scaling to numeric font sizes, as sometimes you need a value between two named sizes and are forced to use a numeric size for text. Some kind of additional property/syntax would probably be required.

Suggestion: Make all fonts scale with accessibility zoom as it currently does (to also ensure backwards compatibility), but add some kind of mechanism for preventing this for the special cases where scaling should not be applied.

@abbalooga
Copy link
Author

Suggestion: Make all fonts scale with accessibility zoom as it currently does (to also ensure backwards compatibility), but add some kind of mechanism for preventing this for the special cases where scaling should not be applied.

Is there anything I can do to reach out to developers or coders to find a solution to this? Being able to prevent user scaling of text seems pretty basic and extremely necessary but for the life of me i cannot find a solution!

@XamMattia83
Copy link

Suggestion: Make all fonts scale with accessibility zoom as it currently does (to also ensure backwards compatibility), but add some kind of mechanism for preventing this for the special cases where scaling should not be applied.

Is there anything I can do to reach out to developers or coders to find a solution to this? Being able to prevent user scaling of text seems pretty basic and extremely necessary but for the life of me i cannot find a solution!

I've tried to solve this by settings the display metrics manually. You can insert this call at the begin of MainActivity.cs OnCreate method:

    private void InitTextSize()
    {       
        Configuration configuration = new Configuration();
        configuration.FontScale = (float)1;
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager.DefaultDisplay.GetMetrics(metrics);
        metrics.ScaledDensity = configuration.FontScale * metrics.Density;
        BaseContext.ApplicationContext.CreateConfigurationContext(configuration);
        BaseContext.Resources.DisplayMetrics.SetTo(metrics);
    }

By the way, the "Display.GetMetrics()" method is deprecated now so i'm trying to fix it.

@rudyspano
Copy link

rudyspano commented Jul 13, 2022

Without usage of deprecated method

        private void InitializeTextSize()
        {
            var configuration = new Configuration
            {
                FontScale = 1
            };

            var metrics = Resources.DisplayMetrics;
            metrics.ScaledDensity = configuration.FontScale * metrics.Density;

            BaseContext.ApplicationContext.CreateConfigurationContext(configuration);
            BaseContext.Resources.DisplayMetrics.SetTo(metrics);
        }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants