How to get R.attr.colorPrimary in pre lvl 21 devices

I know you should be able to get the foreground color of the current theme by calling

getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
int color = typedValue.data;

      

However, even with AppCompat v7: 21, this doesn't seem to work in devices up to 21 ("No such static field" at runtime). However, if I try to declare such an attribute somewhere, it says that it is already defined at compile time (the file that it says contains the definition is not contained). So how is it to access the theme colors from code (not in layout files)?

+3


source to share


1 answer


In fact, I was just being stupid. To be used R.attr.colorPrimary

in pre 21.



You cannot use android.R, but rather your application resources.

0


source







All Articles