Reputation: 83
I have defined a custom class:
public class CustomResource extends Resources {}
in order to load custom external colors at runtime. This is working well in the Java code when using getResources().getColor()
.
When loading an XML layout via setContentView()
, which contains references to colors, then getColor()
of the CustomResources is never called when inflating XML resources.
I already overrode getResources
and getSystemService
in the context but getResources().getColor()
simply does not get called by the View constructors when they resolve XML attributes.
It's because obtainStyledAttributes()
from Resource.Theme
is called from within the constructors of Widgets.
I now have no idea what I have to additionally overwrite.
Example: layout.xml contains a reference to drawable/button.xml, button.xml contains a reference to colors/somecolor.
I now need the call from - for example - a TextView
constructor (the inflater creates a TextView by calling the constructor with the xml attributes as parameters) which then calls obtainStyledAttributes()
to use my resources class for resolving colors rather than the TypedArray
magic that is currently happening in obtainStyledAttributes()
.
Upvotes: 4
Views: 2093
Reputation: 11190
Yes. I have code for this here.
https://github.com/slightfoot/android-edge-effect-override/blob/master/EdgeEffectOverride.java
Upvotes: 4