How programically increase and decrease text size of TextView widget in Android 14

25 views Asked by At

I'm beginner in Android Studio development, and I would like to programically increase and decrease text size of TextView widget in the range of +2 and -2 in SP unit.

This code works perfectly in Android lower than 14, but does't work in Android 14:

INCREASE

float var_SkalaTekstu = this.getResources().getDisplayMetrics().scaledDensity;
float var_WielkoscTekstu = tv_TekstPrzyslowia.getTextSize();
var_WielkoscTekstu += 2;
tv_TekstPrzyslowia.setTextSize(TypedValue.COMPLEX_UNIT_SP, var_WielkoscTekstu / var_SkalaTekstu);

DECREASE:

float var_SkalaTekstu = this.getResources().getDisplayMetrics().scaledDensity;
float var_WielkoscTekstu = tv_TekstPrzyslowia.getTextSize();
var_WielkoscTekstu += 2;
tv_TekstPrzyslowia.setTextSize(TypedValue.COMPLEX_UNIT_SP, var_WielkoscTekstu / var_SkalaTekstu);

I read about changes in Android 14 and I know that I should use TypedValue.applyDimension and TypedValue.deriveDimension, but i don't know how.

Can you help me solve this problem?

0

There are 0 answers