Android Question How to access existing properties of a CustomView

Widget

Well-Known Member
Licensed User
Longtime User
If I create a new Custom View using Project > Add New Module > Class Module > Custom View
and give it the name of TMyView, it will generate the following code:

B4X:
#Event: ExampleEvent (Value As Int)
#DesignerProperty: Key: BooleanExample, DisplayName: Boolean Example, FieldType: Boolean, DefaultValue: True, Description: Example of a boolean property.
#DesignerProperty: Key: IntExample, DisplayName: Int Example, FieldType: Int, DefaultValue: 10, MinRange: 0, MaxRange: 100, Description: Note that MinRange and MaxRange are optional.
#DesignerProperty: Key: StringWithListExample, DisplayName: String With List, FieldType: String, DefaultValue: Sunday, List: Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday
#DesignerProperty: Key: StringExample, DisplayName: String Example, FieldType: String, DefaultValue: Text
#DesignerProperty: Key: ColorExample, DisplayName: Color Example, FieldType: Color, DefaultValue: 0xFFCFDCDC, Description: You can use the built-in color picker to find the color values.
Sub Class_Globals
    Private EventName As String 'ignore
    Private CallBack As Object 'ignore
    Private mBase As Panel
End Sub

Public Sub Initialize (vCallback As Object, vEventName As String)
    EventName = vEventName
    CallBack = vCallback
End Sub

Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
   
End Sub

Public Sub GetBase As Panel
    Return mBase
End Sub


This is the default CustomView code that it creates. If I use the Designer and add TMyView to an activity and click on TMyView I see a lot of properties that are not defined in code and are probably for the base panel (I think). For example, there are "Text", TextStyle properties and Base Background properties. See the enclosed image.

1) How can I access these properties in code?
2) The TMyView Text shows up when I'm using the WYSIWYG Designer, but when the program is run the TMyView view displays no text. It has the Base Background colors, but no text. Why?

Can anyone clear this up?
TIA
 

Attachments

  • TMyView_Properties.png
    TMyView_Properties.png
    26.5 KB · Views: 212

Widget

Well-Known Member
Licensed User
Longtime User
See the tutorial: https://www.b4x.com/android/forum/threads/b4x-custom-views-with-enhanced-designer-support.62488/

"The passed label includes the text related settings. It is not added to the views tree. You can either ignore it or use its text properties."

Thanks Erel.
Yes I took a look at that yesterday and it does give me the rudimentary label related properties like:
lbl.Typeface
lbl.TextColor
lbl.Color
lbl.Enabled
lbl.Visible
lbl.Gravity
lbl.Text
lbl.TextSize
lbl.Left, Top, Right, Bottom, Height, Width
lbl.Tag​

But how do I access the other Designer properties that show up in the Properties window (see screenshot in original post) like:
lbl.Style
lbl.BackGround =Null ??
lbl.Drawable.CornerRadius
lbl.Drawable.Orientation
lbl.Drawable.FirstColor
lbl.Drawable.SecondColor
lbl.HorizontalAlignment
lbl.VerticalAlignment​

If these properties are not accessible by the custom view using code in DesignerCreateView(), why are they accessible in the Properties window?

TIA
 
Upvote 0
Top