Search code examples
codenameone

How do I change the background color of a specific UIID in theme and all UIIDs derived from the specific UIID are also changed?


I have a theme in my cn1 project. I would like to provide color-style selections to my users. I only have one theme file in my project.

How do I change the background color of a specific UIID in the theme file and all UIIDs derived from the specific UIID are also changed at runtime?

So UI components with UIIDs will also change the background color automatically.


Solution

  • You can't do that in runtime. You can use constants to apply a color change and impact inheritance but CSS in Codename One is a compile time feature not a runtime function. Inheritance is implemented during the theme load process so no runtime change will apply.

    Having said that, there is a hack you can do. A CSS will result in a theme Hashtable (yes it's that old hashtable because that API was designed to run on J2ME devices originally). This hashtable still has the concept of inheritance so if you modify that and apply the theme through there it should work.

    See this question for discussion on manipulating the theme. It's for a font but color is just a Integer RGB object.