Android Question TabWidget Indicator Colors

tipallandgo

Member
Licensed User
Longtime User
Hi, is there a way to change these colors (below is an image I found while searching the web)?

4UJPG.png


I tried TabHostExtras but I can't find anything that can change the colors of the indicators.
 

tipallandgo

Member
Licensed User
Longtime User
I appreciate the help, but only the text gets changed using those methods.

I also tried using an XML file like this:
(the filename is aris_theme_tab_indicator_holo.xml)

B4X:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/aris_theme_tab_unselected_holo" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/aris_theme_tab_selected_holo" />

    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/aris_theme_tab_unselected_focused_holo" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/aris_theme_tab_selected_focused_holo" />

    <!-- Pressed -->
    <!--    Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/aris_theme_tab_unselected_pressed_holo" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/aris_theme_tab_selected_pressed_holo" />

    <!--    Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/aris_theme_tab_unselected_pressed_holo" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/aris_theme_tab_selected_pressed_holo" />
</selector>

and inserted it using this code:

B4X:
Dim r As Reflector
For i = 0 To 2
    r.Target = tbe.GetTagWidget(tb).GetChildTabViewAt(i)
    r.RunMethod2("setBackground", "aris_theme_tab_indicator_holo", "android.graphics.drawable.Drawable")
Next

but all I'm getting is this error:

java.lang.IllegalArgumentException: argument 1 should have type android.graphics.drawable.Drawable, got java.lang.String

I guess I'm missing something in my code but I don't know what that is. :confused:




EDIT: for those who might have the same problem in the future, this is how I solve this.

I inserted the XML file above using this code:

B4X:
Dim ar As AndroidResources
Dim r As Reflector
For i = 0 To 2
    r.Target = tbe.GetTagWidget(tb).GetChildTabViewAt(i)
    Dim bg As StateListDrawable
    bg.Initialize
    bg.AddCatchAllState(ar.GetApplicationDrawable("aris_theme_tab_indicator_holo"))
    r.RunMethod4("setBackground", Array As Object(bg), Array As String("android.graphics.drawable.Drawable"))
Next
 
Last edited:
Upvote 0
Top