Android Question Tab background color using StateListDrawable

Discussion in 'Android Questions' started by geoffschultz, Jun 15, 2015.

  1. geoffschultz

    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.
    Sub Activity_Create(FirstTime As Boolean)
    Dim TabHostExtras1 As TabHostExtras
    Dim x As Int
    Colors.DarkGray, 50)
    Colors.Blue, 50)
    If Not(tbhPages.IsInitialized) Then
    End If
    "Volunteer","home"' index 0   
        tbhPages.AddTab("Customers","customers"' index 1
        tbhPages.AddTab("Donors","donors"' Index 2
    For x = 0 To TabHostExtras1.GetTagWidget(tbhPages).TabCount-1
            setStateList(TabHostExtras1.GetTagWidget(tbhPages).GetChildTabViewAt(x), cdBackgroundSelected, cdBackgroundNotSelected)


    Sub setStateList(p As Panel, selected As ColorDrawable, notSelected As ColorDrawable)
    Dim StateListDrawable1 As StateListDrawable
        StateListDrawable1.AddState(StateListDrawable1.State_Selected, selected)
    End Sub
    And here's the xml file for setting the tab text colors:
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android=
        <item android:state_selected=
    "#ffffff" />
        <item android:state_selected=
    "#ffcccc" />
    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
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice