B4A Library [Class] Custom TabHost

Ricky D

Well-Known Member
Licensed User
Find attached version 1.0 of my Custom TabHost

29-Jun-2012 Added v1.11
- Added get/set CurrentTab

28-Jun-2012 Added v1.1
- Fixed measurement settings to use dip
- Added setLeft, setTop, setWidth, setHeight for the Tabhost
- Added setTabHeaderHeight & setTabHeaderTextSize for the Tab Headers

regards, Ricky


Last edited:

Ricky D

Well-Known Member
Licensed User
Tomorrow I'll add methods to get/set Left, Top, Width & Height.

After that I'll look at customization of the tab headers.

Regards, Ricky

Ricky D

Well-Known Member
Licensed User
Version 1.1 is now up.

Fixes dip settings
Added new set methods for position & size of the tabhost
Added new set methods for tab headers height & textsize

Regards, Ricky

Ricky D

Well-Known Member
Licensed User
New update to v1.11

Added get/set CurrentTab

getCurrentTab accepts a string parameter - put in "index" or "tabname" and it will return the appropriate object

Example strg = th.getCurrentTab("tabname")
or i = th.getCurrentTab("index")

setCurrentTab accepts an object.
Internally the class will set mCurrentTab to the tabname
The object accepts an int for index or string for tabname.
If the tab is valid it will be shown.

regards, Ricky


Active Member
Licensed User

Thanks for the routine - I've found it very useful.

If I may be so bold, I have added the following Sub so that I can check

- if a Tab exists - I can delete it without a message or

- if it doesnt exist - I can add it without a message

Public Sub If_Tab_Exists(TabName As String)
Dim ret As Boolean : ret = False

If mTabs.ContainsKey(TabName) Then
ret = True
End If
Return ret
End Sub

Usage as

If th.If_Tab_Exists("AddTrans") = True Then th.RemoveTab("AddTrans")
If th.If_Tab_Exists("Portfolio") Then
'''''Add Tab Page
end if


New Member
Licensed User
I really like your Class, but in my galaxy note 3 malfunctioned.

The screen density of my phone is 3 and when calculate a coordinate and add * 1dip this are out of the physical dimension of the screen.

Real width: 1080 pixels
mWidth = mAct.Width
nWidth = mWidth / 2
nPos = width * 1dip

Density 3 nWidth = 540 _BUT_ nPos = 1620, position is out of screen

luciano deri

Active Member
Licensed User
Is possible insert a ScrollViev component in a layout display on a page of your tabhost? Tanks.