views:

107

answers:

2

Hi all,

I'm trying to get my tabicon to change when a tab is pressed (i.e. when it changes color when you press the tab, but haven't released yet). I've created a selector as follows:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
    <!-- Non focused states --> 
    <item android:state_focused="false" 
          android:state_selected="false" 
          android:state_pressed="false" 
          android:drawable="@drawable/ic_tab_icon1" /> 
    <item android:state_focused="false" 
          android:state_selected="true" 
          android:state_pressed="false" 
          android:drawable="@drawable/ic_tab_icon2" /> 

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

    <!-- Pressed --> 
    <item android:state_pressed="true" 
          android:drawable="@drawable/ic_tab_icon5" /> 
</selector> 

However, for some reason only the first two states are reached (only icon1 and icon 2 are used). Can anyone tell me what the correct state is for a "pressed but not selected" tab?

*Edited to clarify new situation

A: 

Here is tab_indicator.xml from Android 2.2:

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />

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

    <!-- Pressed -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_press" />
</selector>

You do not have anything where android:state_pressed="true". Try changing your selector to look a bit more like what Android uses.

CommonsWare
I have tried this, but it results in the same. If I only change the first line (all false) to the first icon, and all others to the second, the first icon still keeps showing when the tab is pressed.
Siebe
A: 

this is the default tab_indicator.xml for android. got from this gitkernal. you have to maintain all these states.

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
    <!-- Non focused states --> 
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/ic_tab_north_normal" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ic_tab_north_selected" /> 

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

    <!-- Pressed --> 
    <item android:state_pressed="true" android:drawable="@drawable/ic_tab_north_normal" /> 
</selector> 
Praveen Chandrasekaran
I have tried this, but it results in the same. If I only change the first line (all false) to the first icon, and all others to the second, the first icon still keeps showing when the tab is pressed.
Siebe
@Siebe: I edited the code with the value mentioned on your question.Try this.
Praveen Chandrasekaran
Thank for your comment, but it's still the same. I've changed the icon for all the states to different ones and it seems it never reaches the 3rd, 4th or 5th state, i.e. only the images in the non focused states are used.
Siebe