Creating custom attributes for a custom View
is fairly straightforward. As is creating a custom ActionProvider
. The difficulty is that the ActionProvider
class constructor only has a Context
argument and no AttributeSet
argument, like a custom View
would have. Is there any other way to access the custom attributes from within the constructor, e.g. can I get access to the AttributeSet
object by some other means? Or any other approach to adding custom attributes to a custom ActionProvider
? Any help appreciated. Thanks!
Asked
Active
Viewed 78 times
0
-
"Is there any other way to access the custom attributes from within the constructor" -- do you mean in the menu resource? If so, I think that requires a custom `MenuInflater`. – CommonsWare Jul 19 '16 at 20:11
-
The `LayoutInflator` class has a `getFactory()` method, which has method `onCreateView(..., AttributeSet attrs)`. So maybe I can override that? – Sean Jul 19 '16 at 20:23
-
OK, let's try asking it this way: what "custom attributes" are you referring to? What file would they be in? Where would this file be used? For example, in your linked-to `ActionProvider` gist, they have a menu resource (referring to the provider) and a layout resource (for the provider implementation itself). Which of those would contain your desired custom attributes? – CommonsWare Jul 19 '16 at 20:39
-
In the menu resource, each item could specify a custom attribute. – Sean Jul 19 '16 at 20:51
-
Then a `LayoutInflater` factory will not help you, as a `LayoutInflater` is not involved with inflating menus. – CommonsWare Jul 19 '16 at 20:54
-
So I definitely will need a `MenuInflator`. But I don't have access to that within the `ActionProvider` subclass – Sean Jul 19 '16 at 20:59
-
No, but the `MenuInflater` is involved in creating the instance of the `ActionProvider` itself. The `MenuInflater` could conceivably read the custom attributes, then pass them to the `ActionProvider` by calling setter methods. – CommonsWare Jul 19 '16 at 21:02
-
Unfortunately `MenuInflater` only exposes the method `inflate` though. – Sean Jul 19 '16 at 21:07