Search code examples
androiddimension

How change dimension programmatically?


I have more dimens

<resources>
    <dimen name="tag_text_size">10dp</dimen>
    <dimen name="text_separator_size">15dp</dimen>
    <dimen name="tag_text_count_size">8dp</dimen>
    <dimen name="text_home_page_size">20dp</dimen>
    <dimen name="item_text_head_size">15dp</dimen>
    <dimen name="item_text_time_size">10dp</dimen>
    <dimen name="item_text_price_size">14dp</dimen>
    <dimen name="item_text_address_pattern_size">12dp</dimen>
    <dimen name="item_text_address_size">14dp</dimen>
 <dimen name="setting_text_head_size">24dp</dimen>
  <dimen name="order_text_comment_size">11dp</dimen>
</resources>

and i use this dimen in my XML ..

 <TextView
 android:textSize="@dimen/item_text_head_size" />

...

I want to programmatically change the dimen, it will allow me to change the size of strings everywhere

how can this be solved?


Solution

  • It is impossible to set the values for the dimen variables in your dimen.xml file programmatically from the activity.

    The way to do what you want is to delete your android:textSize attributes and to change the text size at runtime using setTextSize() in Java.