I have a class which extends View
. I want to set gradient as a background color
.
@Override
public void onDraw(Canvas canvas)
{
GradientDrawable gradient1 = new GradientDrawable(Orientation.BOTTOM_TOP, new int[]
{Color.parseColor("#B1FCA9"),Color.parseColor("#29C413")});
gradient1.setShape(GradientDrawable.RECTANGLE);
gradient1.setCornerRadius(10.f);
GradientDrawable gradient2 = new GradientDrawable(Orientation.BOTTOM_TOP, new int[]
{Color.parseColor("#29C413"),Color.parseColor("#B1FCA9")});
gradient2.setShape(GradientDrawable.RECTANGLE);
gradient2.setCornerRadius(10.f);
if(!Const.currentLevel.isBonusLevel())
canvas.drawBitmap(Const.backgroundBitmap, 1, 1, null);
else if(this.bonusPicFrame == 0)
gradient1.draw(canvas);
else
gradient2.draw(canvas);
}
gradient1
should appear on my screen but the screen is white.
What is the problem?