I have one textview
and it has size as 32sp
in xml
.
android:textSize="32sp"
I wanted to change it as 28sp
programmatically. So i used the below code.
txt.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.twenty_eight_sp));
But the above code is adding the 28sp
to 32sp
. So the font became too large. I don't want to add the font size, I want to set a new font size.
Can anyone suggest me.
You have to change it to TypedValue.COMPLEX_UNIT_PX
because getDimension(id)
returns a dimen
value from resources and implicitly converted to px
.
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimension(R.dimen.result_font));
txt.setTextSize(TypedValue.COMPLEX_UNIT_SP,getResources().getDimension(R.dimen.twenty_eight_sp));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With