It is recommended to use TabStripViewPager for new projects: https://www.b4x.com/android/forum/threads/63975/#content
The TabHost view is a very important view. It allows you to add several layouts into the same activity.
The designer currently doesn't support adding views directly to the TabHost.
You can only add the TabHost and set its layout:
There are several ways to add tab pages. Usually it is recommended to create a layout file in the designer for each page and then load it.
The designer treats every layout file separately. It is your responsibility to set the views names to distinct names (this is only required for views that you plan to access programmatically).
This is done with AddTab or AddTabWithIcon.
Example:
AddTabWithIcon receives two bitmaps. There are actually two icons. One when the tab is selected and one when the tab is not selected. The guidelines recommend creating a dark version for the selected icon and a light version for the not selected icon.
You can manually change the selected tab by setting the CurrentTab property.
The example is attached.
Project is available here: http://www.b4x.com/android/files/tutorials/TabHost.zip
The TabHost view is a very important view. It allows you to add several layouts into the same activity.
The designer currently doesn't support adding views directly to the TabHost.
You can only add the TabHost and set its layout:
There are several ways to add tab pages. Usually it is recommended to create a layout file in the designer for each page and then load it.
The designer treats every layout file separately. It is your responsibility to set the views names to distinct names (this is only required for views that you plan to access programmatically).
This is done with AddTab or AddTabWithIcon.
Example:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Dim bmp1, bmp2 As Bitmap
bmp1 = LoadBitmap(File.DirAssets, "ic.png")
bmp2 = LoadBitmap(File.DirAssets, "ic_selected.png")
TabHost1.AddTabWithIcon ("Name", bmp1, bmp2, "page1") 'load the layout file of each page
TabHost1.AddTab("Color", "page2")
TabHost1.AddTab("Animal", "page3")
End Sub
You can manually change the selected tab by setting the CurrentTab property.
The example is attached.
B4X:
Sub Process_Globals
End Sub
Sub Globals
Dim TabHost1 As TabHost
Dim txtName, txtAnimal, txtColor As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Dim bmp1, bmp2 As Bitmap
bmp1 = LoadBitmap(File.DirAssets, "ic.png")
bmp2 = LoadBitmap(File.DirAssets, "ic_selected.png")
TabHost1.AddTabWithIcon ("Name", bmp1, bmp2, "page1") 'load the layout file of each page
TabHost1.AddTab("Color", "page2")
TabHost1.AddTab("Animal", "page3")
End Sub
Sub Activity_Pause (Finishing As Boolean)
End Sub
Sub Activity_Resume
End Sub
Sub btnNext1_Click
TabHost1.CurrentTab = 1 'move to next tab
End Sub
Sub btnNext2_Click
TabHost1.CurrentTab = 2 'move to next tab
End Sub
Sub btnDone_Click
Dim sb As StringBuilder
sb.Initialize
sb.Append("You have entered:").Append(CRLF)
sb.Append("Name: ").Append(txtName.Text).Append(CRLF)
sb.Append("Color: ").Append(txtColor.Text).Append(CRLF)
sb.Append("Animal: ").Append(txtAnimal.Text)
Msgbox(sb.ToString, "")
End Sub
Sub TabHost1_TabChanged
Activity.Title = "Current Tab = " & TabHost1.CurrentTab
End Sub
Project is available here: http://www.b4x.com/android/files/tutorials/TabHost.zip
Last edited: