7

I was reading Ha Duy Trung's tutorial Supporting multiple themes in your Android app and in it he has the following snippet for values/attrs.xml:

<attr name="themedMenuStoryDrawable" format="reference" />
<attr name="themedMenuCommentDrawable" format="reference" />

Where is this <attr> element actually documented? Looking in the Android API Guide Providing Resources, I cannot find any mention of this type of element.

I did find a mention of <attr> elements in Creating a View Class, but there they all appear inside of <declare-styleable> elements, and there is hardly any explanation of how these elements work.

Is there proper reference documentation for the <attr> element? If not, then:

  • What does it mean to have an <attr> element directly under <resources>?
  • What is the meaning of the format attribute, and what values can it take?
  • What other XML attributes can <attr> take?
  • Can <attr> appear as the child of anything other than <resources> and <declare-styleable>?

I'd specifically like to know how to use <attr> in the context of theming (rather than custom views) though documentation of how it works in general would be even better.

Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
  • Duplicate? https://stackoverflow.com/questions/3441396/defining-custom-attrs – Adam S Jul 23 '17 at 18:16
  • Yeah, I think that answers all four of your bullets (also - suprisingly still minimal documentation, 7 years later...). – Adam S Jul 23 '17 at 18:25
  • @AdamS While some of the info those answers is useful, that question, and its answers are focused on implementing custom attributes for custom views, which is what the Creating a View Class page I linked to also discusses. That isn't what the tutorial I linked to is doing, and it isn't really clear to me how to get from the use-case described on those pages to the behavior described in the tutorial I linked to. – Laurence Gonsalves Jul 23 '17 at 18:33
  • Hmm, I see, you're looking to understand how (or perhaps, _why_?) attributes work with theming (vs providing properties to a custom view inside the layout). – Adam S Jul 23 '17 at 18:40
  • @AdamS yes. I was hoping for reference docs to understand how attr works in general, but my immediate goal is to understand the specific case of theming. I wish the Android documentation team would put at least half the effort into writing complete references that they put into writing overly specific tutorials. – Laurence Gonsalves Jul 23 '17 at 18:47
  • I'm having trouble putting into words exactly what I'm thinking, and I believe that is because I am confused about what you are confused about. When you say "my immediate goal is to understand the specific case of theming", I don't really know what you mean. Is it that you want to know why `` can be declared inside a ` – Ben P. Jul 24 '17 at 03:42
  • @BenP. Through experimentation and scouring various tutorials I've been able to infer answers to some of my questions, though even more have been raised. I feel like a blind man groping at an elephant. Why are there no reference docs? For example, I now know that the value of an `` is determined by the `` with the same name in the ` – Laurence Gonsalves Jul 25 '17 at 19:44
  • @BenP. I don't understand is how precedence/cascading work. A ` – Laurence Gonsalves Jul 25 '17 at 19:44
  • @BenP. Also, where can I find a complete list of system themes and support library themes? What attrs do they contain, how do they support overriding, and where an I expected to use each of them? This all seems to be spread across various random tutorials and blog posts rather than in reference docs. – Laurence Gonsalves Jul 25 '17 at 19:45

0 Answers0