The font size for Android applications changes according to the specified font size in the settings

I developed an Android application for working with small, medium, and large devices.

But recently I ran into the following problem.

When I go to settings and change the font size to Extra large , and not the default Medium size [Settings β†’ Display β†’ Font Size], my application font size also increases and the layouts become messy.

Someone had previously experienced this and would be grateful for any Idea for a solution that would not continue this confusing situation.

edits ...

I used the "sp" units to determine all font sizes in the application ...

+4
source share
3 answers

Has anyone experienced this before

This is what sp gives you: auto-scalable fonts based on a user-selected font scale.

and I would be grateful for any Idea for a solution that would not continue this confusing situation.

Ideally, you should fix your GUI implementation so that you can make changes to the font size. If the user requested large fonts, your application should support this. This is no different than developing a web application that takes into account browser font size changes.

As a last resort, stop using sp units, but then don’t complain if your users complain that you are not following the required font scale.

See this blog post for more details.

+5
source

I had a problem myself in widgets. There is no place to allow the user to say anything about the font size. The solution is pretty simple:

  • Use dp instead of sp.

Then you will get the correct scaling in accordance with the resolution on dpi on different screens, but it will not change depending on the font size selected by the user.

+4
source

You must redefine this method in your work. When a user changes the Display or TextSize screen, he changes the system configuration parameters, and then your application also selects these configuration parameters, and in the whole application the font size becomes larger or smaller. This may disrupt the appearance of your applications. If you want to set up the same configurations, you can implement the code below. You can change the font size by setting config.fontScale = your choice; You can check on fontScale on different screen sizes.

 @Override protected void attachBaseContext(Context newBase) { Log.d(TAG, "attachBaseContext: "); super.attachBaseContext(newBase); Log.v(TAG, "attachBaseContext: Applying new configuration"); Resources res = newBase.getResources(); Configuration config = new Configuration(); config.fontScale = 1.0f; res.updateConfiguration(config, res.getDisplayMetrics()); } 
0
source

All Articles