简体   繁体   中英

How to make the android LayoutInflater use my Custom Resources

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM