Android v4 support library: 22+ pre Lollipop crashes on attr / in drawables

I experienced the strange effect associated with shapes with lib support attributes. I have a code that crashes every time during inflation.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:width="26dp" android:height="26dp"/> <solid android:color="?attr/colorPrimary"/> 

Note. I used? attr / colorPrimary as color. If i use

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:width="26dp" android:height="26dp"/> <solid android:color="@color/primary"/> 

It works great without any glitches. The problem is only in devices with a lower version of Android than 5.0. I am using the following lib support

 compile 'com.android.support:support-v4:22.2.1' 

Has anyone found a reason why this is happening? Is this a bug in the support library?

+5
source share
1 answer

<solid android:color="?attr/colorPrimary"/> Indicates a private color (was not publicly available) in the Android code, it may not exist in some API.
As long as <solid android:color="@color/primary"/> will indicate a color in your project, perhaps you only have the primary color name in the values โ€‹โ€‹of the -21 folder, so it only crashes in versions below 5.0
I think you should try this: <solid android:color="@android:attr/colorPrimary"/> to make sure the attribute exists.
Hope this helps.

+2
source

All Articles