When i present my textview, i setup a font size of say 18. But if the user set in his phone setting to use a large font size, then my textview will be show with font much bigger than 18. How to force My text view to show with a font size exactly of 18 ?
Asked
Active
Viewed 1,077 times
1
-
1"then my textview will be show with font much bigger than 18" -- the user is asking for larger fonts for a reason. Please allow the user to resize the fonts in your app. – CommonsWare Apr 17 '17 at 18:59
-
not possible because my app depend of bitmap that i can't enlarge :( and often i see that this is because of misc-configuration of the user in his font settings (all case i see was this) – Apr 17 '17 at 19:02
1 Answers
2
It is because you are using 18sp. If you will use 18dp then it will not change the font size. But for font sizes "sp" is preferable so that user can increase or decrease the font size. For more details check this link,
For your case, You can use this,
You can use:
float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 18, getResources().getDisplayMetrics());
editText.setTextSize(pixels);
Now the value of pixels is equivalent to 18dp at the device's current screen density.
The TypedValue contains other similar methods that help in conversion.
-
How to use SP ? actually i setup the font size using setTextSize() that requiered an float value – Apr 17 '17 at 19:04
-
If i set 18 it's will not work, but if i set 18 / 3 (IE ScreenScale) then it's work – Apr 17 '17 at 19:49
-
OK, i found how to do: setTextSize((TypedValue.COMPLEX_UNIT_DIP, 18); :) thanks Shivan ! can you also make +1 to my question because i need min 15 to make that my vote are visible – Apr 17 '17 at 19:57
-
Thanks shivan, i already does, but my vote will be visible only when i will have a total of +15 ... this why i ask about the +1 :) – Apr 18 '17 at 08:13
-
Confirmed (Android 4 and 9). Sp will adapt to text scale settings dp will not. Same size when scale = 1.0. – FrankKrumnow Oct 06 '20 at 10:02