' 1. Declare the component and your label/panel in Class_Globals
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private MySegment As B4XDaisySegment ' Ensure this is added in your designer or initialized in code
Private xlblLog As B4XView
End Sub
' 2. Initialize and configure in B4XPage_Created
Private Sub B4XPage_Created(Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage") ' Assuming MySegment is on this layout
' -- Configure Visual Properties --
MySegment.ActiveColor = "primary" ' Sets the active button color theme [7]
MySegment.Rounded = "full" ' Gives the container a modern pill shape [8]
MySegment.Shadow = "sm" ' Adds a subtle drop shadow [8]
MySegment.ButtonLayout = "icon-start" ' Positions icons before the text [8]
' -- Add Buttons to the Segment --
' You can add buttons with Values, Text Labels, and SVG Icon Paths
MySegment.AddLabel("opt_home", "Home") ' Text only [9]
MySegment.AddLabel("opt_favs", "Favorites")
MySegment.AddLabel("opt_settings", "Settings")
' -- Refresh the View --
' Always call Refresh after updating properties or adding buttons!
MySegment.Refresh [10]
End Sub
' 3. Trap the Event
' The component triggers a 'Changed' event passing the selected 'Value' [1]
Private Sub MySegment_Changed(Value As String)
Log("User selected segment: " & Value)
If xlblLog.IsInitialized Then
xlblLog.Text = "Segment Changed: " & Value [11]
End If
' Example of handling logic based on selection:
Select Case Value
Case "opt_home"
' Show Home Panel
Case "opt_favs"
' Show Favorites Panel
Case "opt_settings"
' Show Settings Panel
End Select
End Sub