Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
'You can use more color combinations to generate the gradient.
SetGradientBackground(Root, Array As Int(xui.Color_Red, xui.Color_Yellow), "LEFT_RIGHT")
End Sub
Private Sub B4XPage_Resize (Width As Int, Height As Int)
'Only when a resize of the page occurs (ex.B4J)
SetGradientBackground(Root, Array As Int(xui.Color_Red, xui.Color_Yellow), "LEFT_RIGHT")
End Sub
Public Sub SetGradientBackground(vPanel As B4XView, Clrs() As Int, Orientation As String)
Dim bc As BitmapCreator
bc.Initialize(vPanel.Width / xui.Scale, vPanel.Height / xui.Scale)
bc.FillGradient(Clrs, bc.TargetRect, Orientation)
'Remove view if exists for resize
For Each v As B4XView In vPanel.GetAllViewsRecursive
If v.Tag = vPanel Then v.RemoveViewFromParent
Next
Dim iv As ImageView
iv.Initialize("")
Dim xiv As B4XView = iv
vPanel.AddView(xiv, 0, 0, vPanel.Width, vPanel.Height)
xiv.Tag = vPanel
xiv.SendToBack
bc.SetBitmapToImageView(bc.Bitmap, xiv)
End Sub