I know in Android that you can scale the images based on screen densities. For instance, if mdpi is the baseline,
- hdpi = 1.5 * mdpi
- xhdpi = 2 * mdpi
- xxhdpi = 3 * mdpi
- xxxhdpi = 4 * mdpi.
Are there similar values for font size?
I know in Android that you can scale the images based on screen densities. For instance, if mdpi is the baseline,
Are there similar values for font size?
what you need to do is to perform a conversion using the scaleDensity
(here the documentation) value, member of the DisplayMetrics
class. From the documentation
A scaling factor for fonts displayed on the display. This is the same as density, except that it may be adjusted in smaller increments at runtime based on a user preference for the font size.
Exactly the same values might be used for font size
android:textSize="18dp"
Although it's recommended to use sp
(scale independent pixels). It's almost the same thing as dp
, but it might scale-up based on user accessibility settings (for instance, if you haw low vision, you can scale-up font size affecting how sp
is calculated). So, in the end it becomes:
android:textSize="18sp"
Once again, if you're using default settings, 1dp == 1sp
res
foldervalues-ldpi
values-mdpi
values-hdpi
values-xhdpi
values-xxhdpi
dimens.xml
in each folder.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="font_size">72sp</dimen>
</resources>
Depending of Screen density change the font size.