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 object, or any other object in onDraw() as it can lead to performance issues. (Android Studio will probably warn you) Instead, make it global and initialize it in your class constructor like so:

public class CustomView extends View {
    private Paint paint;
    public CustomView(Context context) {
        paint = new Paint();
    protected void onDraw(Canvas canvas) {
        // ...

Feedback about page:

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

Table Of Contents