I have this xml drawable. But unfortunately there is a crash when this xml is loaded... due to my shape class "ExtOvalShape":
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<com.xxx.ui.widget.drawable.shapes.ExtOvalShape android:state_selected="true">
<solid android:color="@color/theme_accent_1" />
<stroke android:width="1dp" android:color="@color/background_4" />
<size android:height="@dimen/part_number_value" android:width="@dimen/part_number_value" />
</com.xxx.ui.widget.drawable.shapes.ExtOvalShape>
<com.xxx.ui.widget.drawable.shapes.ExtOvalShape android:state_selected="false">
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="@color/background_4" />
<size android:height="@dimen/part_number_value" android:width="@dimen/part_number_value" />
</com.xxx.ui.widget.drawable.shapes.ExtOvalShape>
</item>
</selector>
How to overload a shape into a drawable xml?
For information my class (it's just to test):
public class ExtOvalShape extends OvalShape {
@Override
public void draw(Canvas canvas, Paint paint) {
super.draw(canvas, paint);
}
}
As far as I know it is not possible to use custom XML elements or extend in any way the existing ones in Android drawable files. You have to stick with the
<shape>tag.What you can do instead is applying programmatically your custom shape, something like: