0

I want to change the textsize inside a style at run time. Can anyone suggest me how to achieve it. Here is the style "TitleView" in which textsize attribute is defined. I want to change it from 20sp to any other value at run time.

<style name="TitleView">
    <item name="android:textSize">20sp</item>
</style>

I want to do it because I've 4 types of textview with different textsize. and In my app user can choose the textsize. So I've changed the text size of other view in relative to the user entered textsize. Thanks in advance.

Prithniraj Nicyone
  • 5,021
  • 13
  • 52
  • 78

2 Answers2

0

You cannot change style attribute at run time.

If you are just trying to change the text size just do:

textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);

this will change your text size and you can do this at any time you want. It is not necessary to change your style attribute. For setting text size at runtime see this

Community
  • 1
  • 1
Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64
-1

Edit: The poster has altered the original question. This answer is no longer directly applicable.

This cannot be done. The styles along with all the other resource values are all compiled into R.java at compile time.

Instead you could you create two styles and switch the style at runtime using setTextAppearance

Stephen
  • 4,041
  • 22
  • 39