Android Code Snippet Get TabHost Tab Height

For a current project I needed to get the height of the tabs on the TabHost. I was struggling with this for a while so I thought I would share this code snippet.

This sub returns the height (in pixels I believe) of the tabs on the TabHost (in this case my TabHost is called "tabMain").

B4X:
Sub GetTabHeight() As Int
    Dim Reflector1 As Reflector
    Dim h As Int = -1   
   
    Reflector1.Target = tabMain
   
    Dim TabWidget As Object
    TabWidget = Reflector1.RunMethod("getTabWidget")
    Reflector1.Target = TabWidget
   
    Dim TabIndicator As View
    TabIndicator = Reflector1.RunMethod2("getChildAt", 0, "java.lang.int")
    Reflector1.Target = TabIndicator
   
    Dim lp As Object
    lp = Reflector1.RunMethod("getLayoutParams")
    Reflector1.Target = lp
       
    h = Reflector1.GetField("height")
   
    Return h
End Sub
 

qsrtech

Active Member
Licensed User
Longtime User
Thanks for the snippet. It doesn't seem to include the height of the tab indicator line, atleast on my 4+ devices.
 
Top