Thursday, February 21, 2019

Android fix font size

Many users like go to phone setting and set their font size dislay to large, even extra large. If you don’t fix it in your app, a button in nomal font size will look like this. 

But in extra large font size it will look like this.
To fix it, we do this in code.
Textview.setTextSize(android.util.TypedValue.COMPLEX_UNIT_DIP, 15);
Or with a Button
Button.setTextSize(android.util.TypedValue.COMPLEX_UNIT_DIP, 15);
You can also choose another TypedValue like COMPLEX_UNIT_PT for pixel, and COMPLEX_UNIT_IN for inches
 

Now text size will be preserve even when user change their font size.

No comments:

Post a Comment