Android Question Elevation Color

Blueforcer

Well-Known Member
Licensed User
Longtime User
You can change shadow colors on Views starting API 28 (Pie) with
View#setOutlineAmbientShadowColor(int color)
and
View#setOutlineSpotShadowColor(int color)
if you use elevation.

How can i use it in B4A?

i tried

B4X:
    Dim card As B4XView = xui.CreatePanel("card")
    card.SetLayoutAnimated(0,0,0,100dip,100dip)

    Dim Offset As Float = 5
    card.As(JavaObject).RunMethod("setElevation", Array(Offset))

    card.As(JavaObject).RunMethod("setOutlineAmbientShadowColor",Array(xui.Color_Red))

But its not working:
java.lang.RuntimeException: Method: setOutlineAmbientShadowColor not found in: anywheresoftware.b4a.BALayout
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Card is what? A Panel?

Have you tried to cast it to a View?
B4X:
    Dim j As JavaObject = Card.As(View)
    j.RunMethod("setOutlineAmbientShadowColor",Array(xui.Color_Red))
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Works fine here:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim card As B4XView = xui.CreatePanel("card")
    Root.AddView(card,0,0,100dip,100dip)
    card.Color = xui.Color_Blue
    Dim Offset As Float = 30dip
    card.As(JavaObject).RunMethod("setElevation", Array(Offset))
    card.As(JavaObject).RunMethod("setOutlineAmbientShadowColor",Array(xui.Color_Red))
End Sub

Though I don't see any change in the shadow color.
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Works fine here:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim card As B4XView = xui.CreatePanel("card")
    Root.AddView(card,0,0,100dip,100dip)
    card.Color = xui.Color_Blue
    Dim Offset As Float = 30dip
    card.As(JavaObject).RunMethod("setElevation", Array(Offset))
    card.As(JavaObject).RunMethod("setOutlineAmbientShadowColor",Array(xui.Color_Red))
End Sub

Though I don't see any change in the shadow color.
Seems like its depending on the emulator i used.
It works on a real device.

We also need to use setOutlineSpotShadowColor in order to show the color

B4X:
Dim card As B4XView = xui.CreatePanel("card")
    Root.AddView(card,100dip,100dip,100dip,100dip)
    card.Color = xui.Color_Blue
    Dim Offset As Float = 30dip
    card.As(JavaObject).RunMethod("setElevation", Array(Offset))
    card.As(JavaObject).RunMethod("setOutlineAmbientShadowColor",Array(xui.Color_Red))
    card.As(JavaObject).RunMethod("setOutlineSpotShadowColor",Array(xui.Color_Red))

Maybe this function can be added to the B4XView class :)
like
B4X:
card.setElevation(30dip,xui.Color_Red)
With
 
Upvote 0
Top