Reputation: 33
I have a shape in one of my xml drawables that uses the styles of my themes.xml file:
<shape android:shape="oval">
<gradient
android:gradientRadius="134dp"
android:startColor="?colorPrimary"
android:centerColor="#000000"
android:endColor="#000111"
android:type="radial" />
</shape>
As you can see startColor uses the colorPrimary attribute. However, when I launch the app in the Android Studio emulator it crashes without build error. When I replace ?colorPrimary by a random hex color everything seems to be fine. I'm using API 24 and as far as I know you can use ?colorVariant for >API 21. Not sure what I'm doing wrong here.
Upvotes: 0
Views: 326
Reputation: 118
use something like this android:startColor="@color/purple_500"
see your colors.xml and call your colors from there
OR
If you want to use 2 colors for day and night go into your project directory resources folder(res)
and create new folder name drawable-night
and copy your shape.xml
from drawable
and paste it in drawable-night
go to android studio now you have 2 shape.xml
files one is night and the other one is for day add colors like you want to add like for
shape.xml add android:startColor="@color/purple_500"
and for shape.xml(night) add android:startColor="@color/purple_200"
Upvotes: 1