Setting A Color Based On Theme
I have an accent color that I use through out my layouts. I have it defined as a style that I apply to a TextView. My application lets the user choose between a dark theme and a l
Solution 1:
The way I resolved this was by creating subclasses of the android.widget.TextView. I created a TextViewAccented and a TextViewWarning. I use these TextViews in my XML where I want the accent or warning color. I remove any color references from the XML.
The subclasses contain the three default constructors. All three constructors call a private method called setColor(). setColor() then inspects the selected theme and can use the desired shade based on the currently selected theme.
It's a fairly clean mechanism, but it's hard to believe that I can't code this in a theme. That seems exactly what a theme should be for.
Post a Comment for "Setting A Color Based On Theme"