How do I clear the canvas in my custom android view?

Newbie to Android, struggling with updating canvas in custom view.

This may have a very simple answer, but so far I have not found it! I draw a path of about 2000 points the first time through onDraw. That is fine. Then the path changes, and I need to draw the new path, and get rid of the old path. But everything I try results in the old path remaining.

I thought there would be a simple 'clear canvas' call but no. I found a reference to _graphics.removeAll(_graphics); but that gives me build errors cannot resolve reference etc.. So is that a valid call, and how do I get it to build? Or is there a simple way !!

Upvotes: 0

Views: 1943

Answers (1)

Matt Clark
Matt Clark

Reputation: 28599

The most simple way, is to just fill the canvas with the background color of your choosing.

c.drawColor(Color.BLACK);

If you are looking for canvas transparency, you can also use this

c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR)

Upvotes: 3

Related Questions