Android Question [SOLVED] Shadow in BBLabel

asales

Expert
Licensed User
Longtime User
I use the Label in B4A and B4i with functions that apply a shadow effect (setShadowLayer in B4A and SetShadow in B4i).

Due the differences in CSBuilder in this platforms, I started to use the BBLabel, but I could not apply the shadow effect.

Is possible to create a cross-platform shadow effect in BBLabel?

Thanks in advance for any tips.
 
Solution
1768976614264.png



1. Depends on B4XBitmapEffects.
2. Set BBLabel.DisableResizeEvent = True
B4X:
Private Sub AddShadow (Lbl As BBLabel, OffsetX As Int, OffsetY As Int, ShadowColor As Int)
    Dim fiv As B4XView = Lbl.ForegroundImageView
    Dim bc As BitmapCreator = Effects.CreateBC(fiv.GetBitmap)
    Dim shadow As ARGBColor
    bc.ColorToARGB(ShadowColor, shadow)
    For x = 0 To bc.mWidth - 1
        For y = 0 To bc.mHeight - 1
            If bc.IsTransparent(x, y) Then Continue
            bc.SetARGB(x, y, shadow)
        Next
    Next
    Dim iv As B4XImageView = XUIViewsUtils.CreateB4XImageView
    iv.mBackgroundColor = xui.Color_Transparent
    iv.ResizeMode = "NONE"
    iv.mBase.Tag = "shadow"
    If Lbl.mBase.NumberOfViews > 1 And...

Erel

B4X founder
Staff member
Licensed User
Longtime User
1768976614264.png



1. Depends on B4XBitmapEffects.
2. Set BBLabel.DisableResizeEvent = True
B4X:
Private Sub AddShadow (Lbl As BBLabel, OffsetX As Int, OffsetY As Int, ShadowColor As Int)
    Dim fiv As B4XView = Lbl.ForegroundImageView
    Dim bc As BitmapCreator = Effects.CreateBC(fiv.GetBitmap)
    Dim shadow As ARGBColor
    bc.ColorToARGB(ShadowColor, shadow)
    For x = 0 To bc.mWidth - 1
        For y = 0 To bc.mHeight - 1
            If bc.IsTransparent(x, y) Then Continue
            bc.SetARGB(x, y, shadow)
        Next
    Next
    Dim iv As B4XImageView = XUIViewsUtils.CreateB4XImageView
    iv.mBackgroundColor = xui.Color_Transparent
    iv.ResizeMode = "NONE"
    iv.mBase.Tag = "shadow"
    If Lbl.mBase.NumberOfViews > 1 And "shadow" = Lbl.mBase.GetView(0).Tag Then
        Lbl.mBase.GetView(0).RemoveViewFromParent
    End If
    Lbl.mBase.AddView(iv.mBase, fiv.Left + OffsetX, fiv.Top + OffsetY, fiv.Width, fiv.Height)
    iv.mBase.SendToBack
    iv.Bitmap = bc.Bitmap
End Sub
 

Attachments

  • ShadowTest.zip
    14.6 KB · Views: 5
Upvote 1
Solution
Top