0

I have a customview and it's background color must be changed every one or two seconds between two colors for example black and white.I can use canvas.drawARGB() and invalidate() to fill canvas with any color.But there are two constant colors that canvas can be colored and calling invalidate every one or two seconds reduces speed.So I guess if I have two canvas that first is colored white and second black and I change whole canvas in onDraw() it may be better than calling canvas.drawARGB().Is my guess true?And is it possible?

Note: My purpose is to avoid of calling canvas.drawARGB() or canvas.setBitmap() or some things else.

Simon Sarris
  • 62,212
  • 13
  • 141
  • 171
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167

3 Answers3

1

If you are trying to change the background color I think a better and simpler approach is which is presented here in the accepted answer:

v.setBackgroundColor(0xFF00FF00); // Where v is your view

Or:

v.setBackgroundColor(Color.GREEN); // Where v is your view

This should be faster than filling the Canvas View with an specific color and then call invalidate()

Community
  • 1
  • 1
Andres
  • 6,080
  • 13
  • 60
  • 110
0

I don't think that changing the whole canvas is possible or wise since the canvas object in ondraw method is all ready prepared for the view and the overhead needed to create a copy of it may be inefficient. However you can use the setBackgroundColor which will apply the color before the ondraw method gets called, see here the drawing paragraph. I think this is the correct approach because you are letting android to do the background assuming that it will use the fastest and the more efficient method.

Hope this helps...

ChD Computers
  • 3,135
  • 3
  • 23
  • 33
0

you should change color of your paint object and pass that paint object to your canvas object.

Onur A.
  • 3,007
  • 3
  • 22
  • 37