textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.result_font));
The following code works, but the R.dimen.result_font
is taken as a much bigger value than it really is. Its maybe about 18sp-22sp or 24sp according to the screen size ... But the size set here is at least about 50sp. Can someone please recommend something ?
To set Android Button font/text size, we can set android:textSize attribute for Button in layout XML file. To programmatically set or change Android Button font/text size, we can pass specified size to the method Button. setTextSize(specific_size).
You need to use another function setTextSize(unit, size) with unit SP like this, tv. setTextSize(TypedValue. COMPLEX_UNIT_SP, 18f);
Use setTextSize() to set values in dp.
I made fixed size column and scrollable textview. Firstly I remove size tag from shape drawable resource. And I add the following code for each column. LayoutParams params = new TableRow.
You have to change it to TypedValue.COMPLEX_UNIT_PX
because getDimension(id)
returns a dimen value from resources and implicitly converted to px.
Java:
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.result_font));
Kotlin:
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.result_font))
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