Question

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().

Was it helpful?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top