Ah yes that'll only modify the tab indicator text color not background color.
I've modified the
TabHost tutorial example:
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")
Dim ColorDrawable1 As ColorDrawable
ColorDrawable1.Initialize(Colors.Blue, 0)
Dim ColorDrawable2 As ColorDrawable
ColorDrawable2.Initialize(Colors.Red, 0)
Dim StateListDrawable1 As StateListDrawable
StateListDrawable1.Initialize
StateListDrawable1.AddState(StateListDrawable1.State_Selected, ColorDrawable1)
StateListDrawable1.AddCatchAllState(ColorDrawable2)
Dim TabHostExtras1 As TabHostExtras
Dim TabIndicator As Panel=TabHostExtras1.GetTagWidget(TabHost1).GetChildTabViewAt(0)
TabIndicator.Background=StateListDrawable1
End Sub
The TabWidget GetChildTabViewAt method returns an android ViewGroup type of object which can be assigned to a b4a Panel.
Now we can set the Panel Background property to a Drawable.
I've used a
StateListDrawable which will appear red when selected and blue at all other times.
The example works BUT i see a problem on my Moto G (kitkat).
When the Panel Background is initially set it overflows the area which it originally occupied.
Click any other tab and the TabHost redraws itself and the Panel background appears as expected.
So try this.
Create a Drawable for the 'selected' state and a Drawable for the 'not selected' state then create a StateListDrawable from these two Drawables.
Now iterate through the tab indicators, setting their Background property to the StateListDrawable.
Martin.