Android Question Custom View / Designer

Guenter Becker

Active Member
Licensed User
Hello,
my question is focused on building a desginerable custom control.

I knew that I can set/retrive the Designer "Text Properties" by code using the *Lbl View" of the "Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)". But I'm missing to do the same with the Background Properties like Drawable/Border a.s.o. because I can not find the belonging Props in the Base Object or the mbase B4XView. I tried mbase.GetView but there is also no access to the Props. By the way I know that I can creat own DesignerProperties by code but I think the requested Props are still there and it will be silly to code them twice.

Question: Does Anyone can tell me how to get and set the Background Properties Values of the mbase View by code? A B4A code snipped would be fine.

Thank You in Advance
Guenter
 

Alexander Stolte

Expert
Licensed User
Longtime User
Question: Does Anyone can tell me how to get and set the Background Properties Values of the mbase View by code? A B4A code snipped would be fine.
B4X:
mBase.Color = xui.Color_Red
or in the designer
1667916715787.png
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Hey
Ok, I know that but what is with the other properties for the border, the gradient and the image? There are no properties listed in mbase for these.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Ok, I know that but what is with the other properties for the border, the gradient and the image? There are no properties listed in mbase for these.
because, mBase is a B4XView. Convert it to a panel and access it via the panel properties.
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Ok, that is what I tried but it did not solve the problem!
If I do it (objPanel = mbase) the Panel View deals only with the properties Color and Background
Background = current Drawable state like ColorDrawable or GradientDrawable or BitmapDrawable
Color = Background Color if Background state is ColorDrawable

What I need to handle by code are all the values of the Background properties of the different Background states, in Detail:

Background = ColorDrawable, Properties: Color/Bordercolor/Borderwidth/radius?
Background = GradientDrawable, Properties: Orientation/First color/Second color?
Background = BitmapDrawable, Properties: ImageFile/Gravity?

Any Idea how to get access? If not I hope erel knew it?
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Hello,
my question is focused on building a desginerable custom control.

I knew that I can set/retrive the Designer "Text Properties" by code using the *Lbl View" of the "Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)". But I'm missing to do the same with the Background Properties like Drawable/Border a.s.o. because I can not find the belonging Props in the Base Object or the mbase B4XView. I tried mbase.GetView but there is also no access to the Props. By the way I know that I can creat own DesignerProperties by code but I think the requested Props are still there and it will be silly to code them twice.

Question: Does Anyone can tell me how to get and set the Background Properties Values of the mbase View by code? A B4A code snipped would be fine.

Thank You in Advance
Guenter
Hello,
sorry but no one could give me a solution.
I found the first step of the solution. It is based on the background property of mbase.as(Panel) and than to use this with the javaobject like this
This is in the DesignerCreatView Sub:
If GetType(mBase.As(Panel).Background) = "anywheresoftware.b4a.objects.drawable.ColorDrawable$GradientDrawableWithCorners" Then
        Dim cd As ColorDrawable = mBase.As(Panel).Background
        Dim jo As JavaObject = cd
        Log($"Radius = ${jo.GetField("cornerRadius")}, BorderWidth = ${jo.GetField("borderWidth")}"$)
    End If

I used the designer Base background properties to set the values for the colordrawable.
On the run I always get the error that the CD/mBase.As(Panel).Background is not initialized.

Anyone could give me an answer how to get the colordraw from the mbase background?
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Hy Erel,
that is what I have done yet but it's not the elegant way because the values always there.
Ok, if it's not possible then I will take it.
Thank you
 
Upvote 0
Top