Android Code Snippet [B4X] Change the background alpha level

Erel

Administrator
Staff member
Licensed User


B4X:
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:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   MakeViewBackgroundTransparent(Label1, 50)
   MakeViewBackgroundTransparent(Label2, 100)
   MakeViewBackgroundTransparent(Label3, 150)
   MakeViewBackgroundTransparent(Label4, 250)
End Sub
 

anOparator

Active Member
Licensed User
I'm hoping the Main Activity background color can be made Transparent, either with XUI or JavaObject.
B4X:
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:
Top