1

I have written a library for displaying Twitter posts after a JSON link has been passed to a Twitter object, and everything is working great except for one small problem: I would like to allow the user to define their own styles to override the default styles from the library, and I would prefer if this could be done via XML rather than pragmatically. I'm able to override things such as background color, but I can't change any of the sub views of the custom listview item, such as the textviews. Is there a way, like in CSS, to change myCustomListView.textview's font color and other properties?

Thank you!

Paul Ruiz
  • 2,396
  • 3
  • 27
  • 47

1 Answers1

2

Android styles are applied during inflating a layout XML file. It's not possible to apply XML styles to a View at runtime after it was inflated.

You would have to read the XML, and execute your own style logic to call methods like setBackgroundColor or setFontSize.

Your best bet would be to see if there is source code somewhere by someone who has already done this.

Reactgular
  • 52,335
  • 19
  • 158
  • 208
  • Bummer, that's what I was figuring I would have to do, but I was hoping for a quick and easy "drop in this style tag into your styles.xml" to make it easier for anyone else using the library. May just have to add functions to my custom list item class to set certain properties and expand them out, but didn't want to force the user to use a builder for each item in a Twitter feed since that could slow things down a bit on older hardware :p Thanks! – Paul Ruiz Jun 03 '13 at 14:32
  • 1
    You can define multiple themes, and change that for a View at runtime. – Reactgular Jun 03 '13 at 14:34
  • Mathew: That took care of it! Thank you. I'm a little retarded, I don't know why I didn't try that in the first place :p – Paul Ruiz Jun 03 '13 at 14:47