Android Question TabStripViewPager background color

Erel

B4X founder
Staff member
Licensed User
Longtime User
This important code allows you to get the labels that make the tab headers:

B4X:
Public Sub GetAllTabLabels (tabstrip As TabStrip) As List
   Dim jo As JavaObject = tabstrip
   Dim r As Reflector
   r.Target = jo.GetField("tabStrip")
   Dim tc As Panel = r.GetField("tabsContainer")
   Dim res As List
   res.Initialize
   For Each v As View In tc
     If v Is Label Then res.Add(v)
   Next
   Return res
End Sub

Example of changing the color of the current tab color:
B4X:
Sub TabStrip1_PageSelected (Position As Int)
   Log($"Current page: ${Position}"$)
   Dim i As Int
   For Each lbl As Label In GetAllTabLabels(TabStrip1)
     If i = Position Then
       lbl.SetColorAnimated(200, Colors.Green, Colors.Yellow)
     Else
       lbl.Color = Colors.Green
     End If
     i = i + 1
   Next
End Sub
Note that you should call TabString1_PageSelected(0) in Activity_Create.

upload_2016-6-21_16-25-51.png
 
Upvote 0

Zockolade

Member
Licensed User
Longtime User
Thanks Erel,

when i use this code

B4X:
For Each lbl As Label In Utils.GetAllTabLabels(TabStrip1)
        lbl.Color = Colors.RGB(39 ,174,96)
Next

I lost underline o_O
 
Upvote 0

Zockolade

Member
Licensed User
Longtime User
B4X:
    For Each lbl As Label In GetAllTabLabels(TabStrip1)
        lbl.Color = Colors.RGB(39 ,174,96)
       Next

Unfortunately the same :(
 
Upvote 0
Top