I´m trying to outsource my custom view into an own library.
Is it possible to get the colorPrimary, colorPrimaryDark and colorAccent attributes outside the scope, maybe at runtime?
Solution
I´ve pointed it out myself.
In xml use:
?attr/attributeName
f.e.
?attr/colorAccent
In code use sth like:
public int getColorValueByAttr(Context context, int attrResId) {
int color = 0;
TypedArray a = null;
try {
int[] attrs = {attrResId};
a = context.obtainStyledAttributes(attrs);
color = a.getColor(0, 0);
} finally {
if (a != null) {
a.recycle();
}
}
return color;
}