I am getting this crash in my app Caused by:
java.lang.IllegalArgumentException: Maximum auto-size text size (24.674995px) is less or equal to minimum auto-size text size (31.5px)
With auto TextView
. How to handle such scenarios gracefully where this case occurs.
I had the same exact issue come up today. Generally speaking whenever I have an issue I can't explain it's a Samsung device. This is no different just like you said. Basically the default theme on Samsung phones sets a minimum size. For us the solution was to specifically add the autoSizeMinTextSize="12dp"
.
Here's another solution depending on your needs and exactly why this is failing for you. The problem is that the user has changed the default font scaling size in the display settings of their device (specifically, they have increased the scale to make the text bigger). Thus the size of the text is larger than the maximum you specified, because the default minimum (since you did not specify a minimum, and that default IS scaled by the user preference) is larger than your maximum.
Specifying a minimum is only the solution if you want to ignore the user's scaling preference. In some cases that is required (in my project we simply cannot honor the user's desired text size in a specific case because that text is bound to visual elements with a fixed size).
The "proper" solution, in that it will honor the user's scaling preference, is to use sp
units (which are density-independent like dp, but they ARE scaled by user preference) instead of dp
units. If you do this you can still only specify a maximum font size, since that maximum will accordingly be scaled along with the default minimum which you did not specify.
So to sum up, you should always use sp
units to specify sizes related to text, unless you specifically want to ignore user scaling due to your layout requirements.
Also, this is easy to test. Just go into Settings->Font and screen zoom->Font Size and set it to "Huge". You should already be testing your layouts against these kinds of variables anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With