My Code is belows,I have tried to learn changing a CustomView to be B4XCustomView
B4X:
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
mBase = Base
Tag = mBase.Tag : mBase.Tag = Me
Dim p As B4XView = xui.CreatePanel("p")
p.Color = xui.Color_Transparent
CornersRadius = DipToCurrent(Props.GetDefault("CornersRadius", 15))
mDisabled = Not(Props.GetDefault("ButtonEnabled", True))
mHaptic = Props.GetDefault("HapticFeedback", False)
pressed = mDisabled
' กำหนดค่าเริ่มต้นของ switch
mSwitchState = Props.GetDefault("InitialValue", False)
If mSwitchState Then
mValue = "on"
Else
mValue = "off"
End If
' โหลดรูปภาพทั้งสองตัว
imgFile1 = Props.GetDefault("SwitchImage1", "switch1.png")
imgFile2= Props.GetDefault("SwitchImage2", "switch2.png")
' If File.Exists(File.DirAssets, imgFile1) Then '<=== For Android is correct
If File.Exists(xui.DefaultFolder, imgFile1) Then '<==I have tried this,but I can't be success
'bmpSwitch1 = xui.LoadBitmapResize(File.DirAssets, imgFile1, mBase.Width, mBase.Height, True) '<=== For Android is correct
bmpSwitch1 = xui.LoadBitmapResize(xui.DefaultFolder, imgFile1, mBase.Width, mBase.Height, True) '<==I have tried this,but I can't be success
Else
bmpSwitch1 = Null
End If
If File.Exists(xui.DefaultFolder, imgFile2) Then
'bmpSwitch2 = xui.LoadBitmapResize(File.DirAssets, imgFile2, mBase.Width, mBase.Height, True) '<=== For Android is correct
bmpSwitch2 = xui.LoadBitmapResize(xui.DefaultFolder, imgFile2, mBase.Width, mBase.Height, True) '<==I have tried this,but I can't be success
Else
bmpSwitch2 = Null
End If
xLBL = Lbl
xLBL.Visible = True
mBase.AddView(xLBL, 0, 0, 0, 0)
mBase.AddView(p, 0, 0, 0, 0)
xLBL.SetTextAlignment("CENTER", "CENTER")
cvs.Initialize(mBase)
Base_Resize(mBase.Width, mBase.Height)
End Sub