Hi,
a neat little snippet showing the slider value while moving. Makes use of the JavaObject libary.
Set the track color and bind a label to the slider.
Bind a label to a slider. The label displays the slider value.
' Set the color of the slider track using RGB colors, e.g. red=255,0,0, green=0,255,0,blue=0,0,255.
a neat little snippet showing the slider value while moving. Makes use of the JavaObject libary.
B4X:
Private Slider1 As Slider
Set the track color and bind a label to the slider.
B4X:
SliderTrackColorRGB(Slider1,0,0,255)
SliderBindLabel(Slider1, "%.0f")
Bind a label to a slider. The label displays the slider value.
B4X:
Sub SliderBindLabel(sldr As Slider, fmt As String)
Dim lblvalue As Label
lblvalue.Initialize("lblvalue")
Dim joSlider As JavaObject = sldr
Dim joLabel As JavaObject = lblvalue
' Get the valueproperty of the slider as StringBinding
Dim vp As JavaObject = joSlider.RunMethodJO("valueProperty", Null).RunMethod("asString", Array(fmt))
' Bind the slider stringbinding to the label
joLabel.RunMethodjo("textProperty", Null).runmethodjo("bind", Array(vp))
' Add the label to the slider thumb
joSlider.RunMethodJo("lookup", Array(".thumb")).RunMethodJo("getChildren", Null).RunMethod("add", Array(lblvalue))
End Sub
' Set the color of the slider track using RGB colors, e.g. red=255,0,0, green=0,255,0,blue=0,0,255.
B4X:
Sub SliderTrackColorRGB(slr As Slider, r As Int, g As Int, b As Int)
Dim joSldr As JavaObject = slr
joSldr.RunMethodJo("lookup", Array(".track")).RunMethod("setStyle", Array($"-fx-background-color:rgb(${r},${g},${b});"$))
End Sub