Android Code Snippet [B4X] Change the background alpha level

Discussion in 'Code Snippets' started by Erel, Aug 17, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]

    Code:
    Private Sub MakeViewBackgroundTransparent(View As B4XView, Alpha As Int)
       
    Dim clr As Int = View.Color
       
    If clr = 0 Then
           
    Log("Cannot get background color.")
           
    Return
       
    End If
       
    View.Color = Bit.Or(Bit.And(0x00ffffff, clr), Bit.ShiftLeft(Alpha, 24))
    End Sub
    Depends on: XUI (or jXUI or iXUI).

    Example:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    Activity.LoadLayout("1")
       MakeViewBackgroundTransparent(Label1, 
    50)
       MakeViewBackgroundTransparent(Label2, 
    100)
       MakeViewBackgroundTransparent(Label3, 
    150)
       MakeViewBackgroundTransparent(Label4, 
    250)
    End Sub
     
    Procesor, PassionDEV, Jaames and 8 others like this.
  2. anOparator

    anOparator Active Member Licensed User

    I'm hoping the Main Activity background color can be made Transparent, either with XUI or JavaObject.
    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    'I have also set Activity color to transparent in Visual Designer
       Activity.LoadLayout("Layout1")
    '   MakeViewBackgroundTransparent(Activity, 25)   ' does not help
    '   MakeViewBackgroundTransparent("", 25)   ' does not help
       Activity.Color = Colors.Transparent   ' not working, black background
    End Sub

    Private Sub MakeViewBackgroundTransparent(View As B4XView, Alpha As Int)
         
    Dim clr As Int = View.Color
       
    If clr = 0 Then
           
    Log("Cannot get background color")
           
    Return
       
    End If
       
    View.Color = Bit.Or(Bit.And(0x00ffffff, clr), Bit.ShiftLeft(Alpha, 24))
    End Sub

    Sub Activity_Resume
    '   Activity.Color = Colors.Transparent   ' not working, black background
    End Sub
    EDIT: Cancelled question. Just found it, thanks for the keyword search tools. -
    https://www.b4x.com/android/forum/threads/transparent-background-with-clip-function.97328/
     
    Last edited: Oct 20, 2018
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