Android Question get text size and typeface by using reflection

Discussion in 'Android Questions' started by ArminKH, Mar 1, 2015.

  1. ArminKH

    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
    Sub TextSize(Target As Object)
    Dim GetTextSize As Reflector
    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
  2. Erel

    Erel Administrator Staff Member Licensed User

    If you are developing with B4A then you should use B4A api. There is no reason to use reflection here.
    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
    ArminKH likes this.
  3. ArminKH

    ArminKH Well-Known Member

    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
  4. klaus

    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.
    mangojack and ArminKH like this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    I agree with Klaus.
    That is not correct. It will not convert a button to a label.
    ArminKH likes this.
  6. ArminKH

    ArminKH Well-Known Member

    Yes you right
    I initilize button by canvas
    And my btn changed to label
    After using canvas1.initialize(activity)
    Now its working
    Last edited: Mar 2, 2015
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice