Creating a Paint

suggest change

You can create a new paint with one of these 3 constructors:

It is generally suggested to never create a Paint, or any other object, in onDraw(), because that can lead to performance issues. Android Studio will probably warn you. Instead, make it a field and initialize it in your class constructor:

public class CustomView extends View {
    
    private Paint paint;
    
    public CustomView(Context context) {
        super(context);
        paint = new Paint();
        //...
    }
    
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(0xFF000000);
        // ...
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents