Skip to content

Instantly share code, notes, and snippets.

@galaxyfeeder
Created October 17, 2013 14:35
Show Gist options
  • Save galaxyfeeder/7026090 to your computer and use it in GitHub Desktop.
Save galaxyfeeder/7026090 to your computer and use it in GitHub Desktop.
public class ColorGradientCircleButton extends View{
private Paint mPaint;
private int width, height;
public ColorGradientCircleButton(Context context) {
super(context);
init();
}
public ColorGradientCircleButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ColorGradientCircleButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
width = getWidth();
height = getHeight();
mPaint = new Paint();
mPaint.setColor(Color.BLACK);
mPaint.setStrokeWidth(1);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(width/2, height/2, height/3, mPaint);
}
public void changeColor(int color){
mPaint.setColor(color);
invalidate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment