Replace resources in whole application
ozodrukh opened this issue · 1 comments
ozodrukh commented
Have someone experience in replacing Resources
in whole application, i need to intercept getDrawable method everywhere
Testing on Genymotion, Android 4.1.1
i need some ideas how to work around
- Approach to wrap context when
attachBaseContext
method called, failed. When inflating views it doesn't works :( - I found really strange behavior that the original(android) views and custom views are getting different types of Context. Cause i made efforts to set background via XML on ImageButton and get Exception, but when i create custom view extended from ImageButton it worked
update on approach 2
hmm, looks like if i define background as an attribute it falls, if do it by code it works
i found what is going on after all, the views calls TypedArray#getDrawable method
public Drawable getDrawable(int index) {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
}
final TypedValue value = mValue;
if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
if (value.type == TypedValue.TYPE_ATTRIBUTE) {
throw new RuntimeException("Failed to resolve attribute at index " + index);
}
return mResources.loadDrawable(value, value.resourceId, mTheme);
}
return null;
}
Now i need to think how to replace loadDrawable method 😞
New plan, going to replace LayoutInflater with custom one and create custom attributes like Calligraphy did