Alex Rivera | Logout

android dynamically change style at runtime

Asked 2010-07-13T21:34:23.783
43

I'd like to make my font sizes configurable but i'd also like to make use of the style tag in my layouts. Is it possible to change the definition of a style at runtime? or is the only option to manually change the individual style elements on each textview etc.?

Edit
Report

1 Answer

19

Changing the style after creating the view is not supported .. so what you can do is:

  1. create a new android xml file of type values
  2. add new theme
  3. add your elements to that theme and their values and save the file

Now, when you are dynamically creating the new view you call the constructor that will allow to define a defStyle. Then, you point to the style ID you have just created by pointing to R."the XML file name"."your style ID"

myTextView.setTextAppearance(getApplicationContext(), R.style.boldText);
answered 2011-02-27T18:11:54.593

Your Answer