I've experienced a strange effect dealing with shape drawables with support lib attributes. I have following code, which 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 have 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 is working fine without any crashes. Issue is only in devices running lower version of Android than 5.0. I am using following support lib
compile 'com.android.support:support-v4:22.2.1'
Anyone found reason why this is happening? Is this a bug in support library?
<solid android:color="?attr/colorPrimary"/>
Points to a private color (was not public) in Android code, maybe it doesn't exist in some API.
While <solid android:color="@color/primary"/>
will point to a color in your project, maybe you have a color name primary
only in folder values-v21 so it's only crashing in versions below 5.0
I think you should try using this:
<solid android:color="@android:attr/colorPrimary"/>
to make sure the attribute exists.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With