Android Question get text size and typeface by using reflection

ArminKH

Well-Known Member
hi i want to get typeface and textsize of an object(a label or button) by reflection
here is my code
B4X:
    Sub TextSize(Target As Object)
        Dim GetTextSize As Reflector
            GetTextSize.Target=Target
            Log(GetTextSize.RunMethod("getTextSize"))
    End Sub
but above code return wrong value
for example when my textsize in label is 16 this sub return 24

and if is possible please help me to find the method of GetTypeface by reflection
tnx
 

ArminKH

Well-Known Member
If you are developing with B4A then you should use B4A api. There is no reason to use reflection here.
B4X:
Sub TextSize(Target As Object) As Double
Dim lbl As Label = Target
Return lbl.TextSize
End Sub


Sub Typeface(Target As Object) As Typeface
Dim lbl As Label = Target
Return lbl.Typeface
End Sub
i do your said way but for example when target is a button after use above subs my button converted to label and thats not is a button
 

klaus

Expert
Licensed User
What exactly do you want to do ? I saw quite some threads and posts about almost the same problem.
So, please explain what is your foundamental problem or concern !
I have the feeling that we are turning in circle. You ask questions for 'detailed problems', but you don't explain your REAL expectations or needs.
I had never the need for any of your requests which couldn't be solved with STANDARD B4A properties or methods.
 

ArminKH

Well-Known Member
I agree with Klaus.

That is not correct. It will not convert a button to a label.
Yes you right
I initilize button by canvas
Canvas1.initialize(lbl)
And my btn changed to label
After using canvas1.initialize(activity)
Now its working
 
Last edited:
Top