I need to draw a simple shape in android
The shape needs to be in circle shape as ImageView drawable, create a ShapeDrawable use canvas
I tried the following but not working
public class MyButton extends ImageButton {
private Drawable iconDrawable;
public MyButton(Context context) {
super(context);
}
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
setImageDrawable(getIconDrawable());
}
/**
* just draw a simple circle
*
* @return
*/
public Drawable getIconDrawable() {
Shape shape = new Shape() {
@Override public void draw(Canvas canvas, Paint paint) {
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(0, 0, 20, paint);
}
};
ShapeDrawable drawable = new ShapeDrawable(shape);
return drawable;
}
}