How do I apply a style programmatically?

后端 未结 5 695
醉梦人生
醉梦人生 2020-12-08 10:46

I have a styles called Red and Green and I have an if statment to find out which to apply, but I don\'t know the code to actually apply a style from the java.

5条回答
  •  攒了一身酷
    2020-12-08 11:48

    You can use the brand new Paris library to apply styles programmatically:

    Paris.style(yourView).apply(condition ? R.style.Green : R.style.Red);
    

    The only caveat is that not all attributes are supported (but many are and support can be added fairly easily by contributing to the library).

    • List of currently supported attributes
    • Installation instructions

    Disclaimer: I'm the original author of the library.

提交回复
热议问题