It is not directly connected with Splitties, but a...
# splitties
i
It is not directly connected with Splitties, but as it is about moving from xml, I'll ask here 🙂 The most common practice to have some set of colors is to put them into
colors.xml
file (something like
<color name="colorBlack">#000000</color>
) But is there any better way having in mind that we try to eliminate xml files in our projects? 🙂 I'm thinking about some helper class with constant values:
Copy code
const val Black = 0x000000.toInt()
Does it sound reasonable? Is it somehow better than xml? Or it really doesn't matter in practice? What do you think?
l
There's already
Color.BLACK
. That said, as long as the colors target only Android, I keep them in xml because I then have coloring in the IDE.
w
How would it work with theming and e.g. dark mode? Btw maybe you’ll find AirBnb’s
Paris
library interesting, I think it’s aiming for styling the views programmatically
i
@wasyl Thanks a lot for a link! Actually I was not thinking about themes at all 😞 In android world I've never seen an app that supports more than one theme (even Gmail/Outlook/Whatsapp). Just checked out - not so many apps support it: https://www.pcmag.com/feature/366170/how-to-set-up-dark-mode-on-your-favorite-apps/38 - but YouTube predictably has dark theme. Theming looks good for me from another point - it makes it harder to miss some attribute and reduces copy-paste for similar components. Do you use theming in your apps? Do you think it is critical to support it? 🙂
It looks like Paris is not a silver bullet - it has many limitations in out-of-box styling support, especially for custom components. Probably that's not their fault - it is a problem of whole android ecosystem built on xml. I've already faced with some troubles when it is not possible to change some property programmatically - only from xml or via reflection...
l
I had cloned Airbnb/Paris to look at it and found it quite over-engineered especially to just circumvent Android limitations. About DayNight theme, here are the well known apps that support them: Slack, Google Calendar, Drive, Keep, Contacts, Phone, Files Go, Photos, Twitter and more. So let me disagree strongly on what you said: "I've never seen an app that supports more than one theme"
r
I’m really ok with having resources like colors in XML files which are basically lists. I’m just not ok seeing views as resources, and in general XML files with more than 1 level
2
i
Thank you guys! Finally it took only 1 day for me to support dark theme - everything that I needed was to support another colors.xml for dark theme 😉 So the best answer for original question is to support colors via xml, as google has already done most of the stuff for us.