Android Question Pages create and gradient color for the background of the pages

Picon

Member
Licensed User
Has anyone made a color gradient for the background of the page / pages?
How to do it?

I also have a problem with understanding how to build new pages in the application:
The first "Start" page is created like this (in the class module: B4XMainPage):

First page "Start":
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("StartPage")
    B4XPages.SetTitle(Me, "Start")
End Sub

The second page is already being created (in the code module):

Second page "Setings":
Public Sub Show
    If pg.IsInitialized = False Then
        pg.Initialize("pg")
        pg.RootPanel.LoadLayout("Setings")
        pg.HideBackButton = True '<-- don't want to allow the user to return to the login screen
    End If
    
    Main.NavControl.ShowPage(pg)
    
End Sub

Which way is better? When to use class modules to add more pages in the application, and when to use regular code modules?
And the question about the background gradient. In B4i Visual Designer there are no such settings as in B4A:

GradientDrawable -> Orientation, First Color and Second Color

I found an example on the forum, but it works only on objects already on the page, but the background of the page itself does not apply.
And it only works in the "Main" regular and basic code module (in Private Sub Application_Start)
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Have you looked at :

The attached example shows how to create 3 pages.

The way you describe is for iOS WITHOUT b4xpages.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Has anyone made a color gradient for the background of the page / pages?
and this can be an alternative B4X?
not tested b4i

Library BitmapCreator
B4X:
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

1644952931580.png
 
Upvote 2
Top