Android Question [B4X] Set gradient to a panel in B4X

Discussion in 'Android Questions' started by mberthe, Jul 16, 2019.

  1. mberthe

    mberthe Member Licensed User

    In b4A I have set a gradient with 3 colors to a panel :

    Code:
    dim panel1 as panel
    Dim dw As GradientDrawable
    Dim colorgris As Int= Colors.RGB(96,96,96)
    Dim clr(3As Int
    clr = 
    Array  As Int(colorgris,Colors.white,colorgris)
    dw.Initialize(
    "TOP_BOTTOM",clr)
    panel1.background= dw

    How make the same in B4X ?
     
  2. sorex

    sorex Expert Licensed User

    I don't think there is a XUI method for it yet. I only used the xui color & border methods so far.

    you'll have to use conditional code for #B4A & #B4i
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Dim clr(3As Int
    clr = 
    Array  As Int(colorgris,Colors.white,colorgris)
    Better:
    Code:
    Dim clr() As Int = Array  As Int(colorgris,Colors.white,colorgris)
    Cross platform solution:

    Code:
    Sub SetGradientBackground(pnl As B4XView, Clrs() As Int, Orientation As String)
       
    Dim bc As BitmapCreator
       bc.Initialize(pnl.Width / xui.Scale, pnl.Height / xui.Scale)
       bc.FillGradient(Clrs, bc.TargetRect, Orientation)
       
    Dim iv As ImageView
       iv.Initialize(
    "")
       
    Dim xiv As B4XView = iv
       pnl.AddView(xiv, 
    00, pnl.Width, pnl.Height)
       xiv.SendToBack
       bc.SetBitmapToImageView(bc.Bitmap, xiv)
    End Sub
    Example:
    Code:
    SetGradientBackground(Panel1, Array As Int(xui.Color_Red, xui.Color_Green, xui.Color_Blue), "TOP_BOTTOM")
     
  4. mberthe

    mberthe Member Licensed User

    Thank you, it works !
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice