Skip to content

Instantly share code, notes, and snippets.

@TakuSemba
Created August 8, 2017 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakuSemba/5a71eca8073f290ab96967a4b98bed8f to your computer and use it in GitHub Desktop.
Save TakuSemba/5a71eca8073f290ab96967a4b98bed8f to your computer and use it in GitHub Desktop.
public class CanvasView extends View {
private Paint backgroundPaint = new Paint();
private Paint paint = new Paint();
public CanvasView(Context context) {
super(context);
}
public CanvasView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public CanvasView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
setLayerType(View.LAYER_TYPE_HARDWARE, null);
// draw all
backgroundPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.background_dark));
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), backgroundPaint);
// hollow a cirlce out of the black brackgroud
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
canvas.drawCircle(getWidth() / 2, getHeight() / 2, 250, paint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment