You need to use the DrawDrawable function and pass it a GradientDrawable object.
B4X:
Dim GD As GradientDrawable
Dim Colours(2) As Int
Colours(0) = Colors.Black
Colours(1) = Colors.White
GD.Initialize("TOP_BOTTOM",Colours)
Canvas1.DrawDrawable(GD,Rect1)