iOS Question Change tabstrip label color when focus

Leni Berry

Active Member
Licensed User
in B4A, tabstripviewpager can do this to change tabstrip color label when it focused :

B4X:
For Each lbl As Label In GetAllTabLabels(tabkategori)
        If i = Position Then
            lbl.TextColor = Colors.White
            strcat=lbl.Text
        Else
            lbl.TextColor = Colors.ARGB(180,255,255,255)
        End If
        i = i + 1
    Next
and procedure for GetAllTabLabels is:

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
is there the similiar way for doing that in B4i Tabstrip?
 

Erel

Administrator
Staff member
Licensed User
Try this:
B4X:
Private Sub Application_Start (Nav As NavigationController)
   'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
   NavControl = Nav
   MainPage.Initialize("MainPage")
   MainPage.RootPanel.LoadLayout("Main")
   NavControl.ShowPage(MainPage)
   TabPages.Initialize
   Dim cs As CSBuilder
   Dim page1, page2, page3 As Page
   
   
   page1.Initialize("page1")
   page1.RootPanel.LoadLayout("Tab1")
   SetAttributedTitle(page1, cs.Initialize.Append("Bing"))
   WebView1.LoadUrl("https://www.bing.com")
   TabPages.Add(page1)
   
   page2.Initialize("page2")
   page2.RootPanel.LoadLayout("Tab1")
   WebView1.LoadUrl("https://www.google.com")
   SetAttributedTitle(page2, cs.Initialize.Append("Google"))
   TabPages.Add(page2)
   
   page3.Initialize("page3")
   page3.RootPanel.LoadLayout("Tab1")
   WebView1.LoadUrl("https://www.duckduckgo.com")
   SetAttributedTitle(page3, cs.Initialize.Append("DuckDuckGo"))
   TabPages.Add(page3)
     
   TabStrip1.SetPages(TabPages)
   
End Sub

Sub TabStrip1_PageSelected (Position As Int)
   For i = 0 To TabPages.Size - 1
     Dim p As Page = TabPages.Get(i)
     Dim lbl As Label = p.TitleView
     
     Dim clr As Int
     If i = Position Then clr = Colors.Red Else clr = Colors.Black
     Dim cs As CSBuilder
     SetAttributedTitle(p, cs.Initialize.Color(clr).Append(lbl.AttributedText.ToString).PopAll)
   Next
   
   Dim no As NativeObject = TabStrip1
   Sleep(50)
   no.RunMethod("reloadPagerTabStripView", Null)
End Sub
 
Top