Reputation:
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 ?
Upvotes: 0
Views: 1380
Reputation: 720
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.
Upvotes: 2