Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

enhancement: better interop with theme attributes #30

Open
pfn opened this issue Jul 29, 2014 · 6 comments
Open

enhancement: better interop with theme attributes #30

pfn opened this issue Jul 29, 2014 · 6 comments

Comments

@pfn
Copy link

pfn commented Jul 29, 2014

this is a downside of moving away from xml, that the xml conveniences such as theme attributes become unavailable. I don't know a good way to handle this yet

@stanch
Copy link
Collaborator

stanch commented Jul 29, 2014

I don’t think themes can be applied programmatically :( However I’ve never been able to use them effectively — personally I find the whole theme XML API (inheritance, composition, namespacing) very confusing. On the other hand, for many cases styling with tweaks works rather well.

@dant3
Copy link

dant3 commented Jul 29, 2014

Actually themes, is just mixed in attribute sets that is passed to views as constructor parameters. This could be done in the code, the process is not much different from supplying a bundle to the Intent, from code standpoint, although I'm not sure how you could convert existing theme.xml to such AttributeSet.

That I'm doing to bypass this limitation without much code (and due to my project is pretty big and complex, with huge legacy), is that I'm just using xml as usual, and then wire views using either Transformer and pattern-matching them (hackish, but works for me), or finding them by id.

@stanch
Copy link
Collaborator

stanch commented Jul 29, 2014

AFAIK there is no way to create AttributeSet programmatically. See for example this SO answer.

Yeah, not using the LayoutBuilding DSL is another way to approach this :)

@dant3
Copy link

dant3 commented Jul 29, 2014

Looking at the documentation, this example exists:

XmlPullParser parser = resources.getXml(myResouce);
AttributeSet attributes = Xml.asAttributeSet(parser);

Given that XmlPullParser is used, that you could do (if you really wish to create themes from code) is create xml from code and so on... So, with proper wrapping around, this still can look like macroid's Bundle API.

@dant3
Copy link

dant3 commented Jul 29, 2014

Even more from docs: AttributeSet is actually just an Interface, so you could implement it as you wish, inspiring by looking at code of Views that are actually reading attributes out of it.

@stanch
Copy link
Collaborator

stanch commented Jul 29, 2014

This is interesting — we could write an implementation of AttributeSet with +, etc — as an alternative to tweaks... I’ll try to poke with it when I have time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants