Размер шрифта HTML для Android в зависимости от плотности экрана - PullRequest
0 голосов
/ 26 марта 2012

Мне нужен способ сказать, является ли устройство LDPI, MDPI или HDPI, установить размер шрифта html равным xeg

if (ldpi){
htmlString.append("<br><p align='center'><font color='Yellow' size='5'>");
}
else if (mdpi){
htmlString.append("<br><p align='center'><font color='Yellow' size='6'>");
}
else if (hdpi){
htmlString.append("<br><p align='center'><font color='Yellow' size='7'>");
}

. Любая помощь будет признательна.

1 Ответ

1 голос
/ 26 марта 2012

Для справки: http://developer.android.com/reference/android/util/DisplayMetrics.html

вы можете получить значение dpi вот так;

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

и сравните свойство density с константами;

int DENSITY_DEFAULT The reference density used throughout the system.
int DENSITY_HIGH    Standard quantized DPI for high-density screens.
int DENSITY_LOW Standard quantized DPI for low-density screens.
int DENSITY_MEDIUM  Standard quantized DPI for medium-density screens.
int DENSITY_TV  Standard quantized DPI for 720p TV screens.
int DENSITY_XHIGH
...