Android Question Tab background color using StateListDrawable

geoffschultz

Member
Licensed User
I wrote an app for internal use only at a charity that I run. We utilize Asus Memo Pads and recently they updated from Kitkat to Lolipop. When this occurred the formatting of the selected tabs changed from having nice rounded different color background to simply underlining the selected tab text. I wanted to reproduce the Kitkat interface look, so I tried setting the background color using StateListDrawable.

When the tabs are initially displayed, they render correctly. As soon as a keyboard pops up when the cursor enters an edittext field, the tab backgrounds are incorrectly rendered as shown below:



If I press one of the tab buttons or if I change the orientation, the tab backgrounds are correctly redrawn.

Here's the core section of code that accomplishes this.
B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    Dim TabHostExtras1 As TabHostExtras
    Dim x As Int
   
    cdBackgroundNotSelected.Initialize(Colors.DarkGray, 50)
    cdBackgroundSelected.Initialize(Colors.Blue, 50)
       
    Activity.LoadLayout("Main")   
   
    If Not(tbhPages.IsInitialized) Then
        tbhPages.Initialize("tbhPages")
    End If
   
    tbhPages.AddTab("Volunteer","home") ' index 0   
    tbhPages.AddTab("Customers","customers") ' index 1
    tbhPages.AddTab("Donors","donors") ' Index 2
   
    TabHostExtras1.setTabHeight(tbhPages, 50)
   
    For x = 0 To TabHostExtras1.GetTagWidget(tbhPages).TabCount-1
        setStateList(TabHostExtras1.GetTagWidget(tbhPages).GetChildTabViewAt(x), cdBackgroundSelected, cdBackgroundNotSelected)
    Next

    tabManager.setTabTextColorStateList(tbhPages, "tbhpages_text_colors")

Sub setStateList(p As Panel, selected As ColorDrawable, notSelected As ColorDrawable)
    Dim StateListDrawable1 As StateListDrawable
    StateListDrawable1.Initialize
    StateListDrawable1.AddState(StateListDrawable1.State_Selected, selected)
    StateListDrawable1.AddCatchAllState(notSelected)
   
    p.Background=StateListDrawable1
End Sub
And here's the xml file for setting the tab text colors:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true"  
        android:color="#ffffff" />
    <item android:state_selected="false"  
        android:color="#ffcccc" />
</selector>
I just have to assume that there's something stupid that I'm just missing here.

Thanks in advance for any help that you can offer.

-- Geoff
 
Top