Can I dynamically change the background color of a switch?

Are you referring to node-red-dashboard ?
Yes there is a way. You can use the template node.

You can read some hints here