I have variable at dimens.xml
<resources>
<dimen name="btn_text_size">12sp</dimen>
</resources>
And i can use it in layout file:
<TextView
android:textSize="@dimen/btn_text_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_tags_complete"
/>
or programmatically
tagButton.setTextSize(c.getResources().getDimension(R.dimen.tag_text_size));
But this 2 methods give different results. I know that getDimension
are based on the current DisplayMetrics associated with the resources.
But what should i do to make this 2 ways looks the same?
getDimensionPixelSize()
. – Luculentsp
= scaled pixels, which will adjust based on the screen metrics and text-scaling factor, right? If you want to make them look the same, you'll need to usedp
. – LuculentsetTextSize()
method. The one you're using expects scaled pixels, while you are providing pixels. Do this instead:setTextSize( TypedValue.COMPLEX_UNIT_PX, getDimensionPixelSize( R.dimen.tag_text_size ) );
– Luculent