Skip to content Skip to sidebar Skip to footer

Text View Returning Wrong Text Size

I need to get the text size of the text view so that I would increment in text size while user pressing the button which indicates that it helps in increasing the text size in the

Solution 1:

The problem is that getTextSize() return the size in pixels, not in sp. So you can convert pixels to sp first then -

tvContentString.setTextSize(TypedValue.COMPLEX_UNIT_SP, new_size);

To convert from pixels to sp use this -

publicstaticfloatpixelsToSp(Context context, float px){
    float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
    return px/scaledDensity;
}

Code taken from here.

Post a Comment for "Text View Returning Wrong Text Size"