views:

86

answers:

2

Hi All,

I have a problem with my tab style. I would like my tab style will look like this.

http://www.technobuzz.net/wp-content/uploads/2010/02/seesmic-android-260-208.png Something goes wrong in my xml ...

The style shows only the colors When selected (see comment). When I use a white icon is the text (text setindicator) white. This also applies to the gray icon.

When the icon color is white the text from the setindicator is then also white.. How can I fix this.

Does anyone have the same tabstyle as the link above and want to share with me Thanks a lot!!

Main.java

intent = new Intent().setClass(this, Settings.class);
     spec = tabHost.newTabSpec("settings").setIndicator("Settings",
            res.getDrawable(R.drawable.tab_settings))
            .setContent(intent);
            tabHost.addTab(spec);


            TabWidget tw = getTabWidget(); 
            for (int i = 0; i < tw.getChildCount(); i++) { 
                    View v = tw.getChildAt(i); 
                    v.setBackgroundDrawable(getResources().getDrawable 
                    (R.drawable.custom_tab)); 
            } 

tab_settings

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/artists_on"
          android:state_selected="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/artists_of" />
</selector>

custom_tab.xml the tab style...

<item android:state_pressed="true" >
    <shape>
        <gradient
            android:startColor="#ea9d32"
            android:endColor="#ffcc50"
            android:angle="270" />
    </shape>
</item>

<!-- WHEN SELECTED --> <!-- HOW CAN I SAID WHEN NOT SELECTED? --> 
    <item android:state_focused="true" >
        <shape>
            <gradient
                android:endColor="#ffcc50"
                android:startColor="#ffcc50"
                android:angle="270" />
        </shape>
    </item>

       <item android:state_focused="false" >
        <shape>
            <gradient
                android:endColor="#ffffff"
                android:startColor="#AAAAAA"
                android:angle="270" />
            <stroke
                android:width="1px"
                android:color="#000000" />
        </shape>
    </item>
</selector>

Thanks a lot!

A: 

Why do you repost the same question over and over again? People have already answered, just look at your other threads.

BlackDragonBE
A: 

You can try changing your custom_tab.xml to include state_focused, state_pressed and state_selected, similar to this:

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
<item android:state_focused="false" 
  android:state_selected="false" 
  android:state_pressed="false" 
  android:drawable="@drawable/tab_focus"/> 
<item android:state_focused="false" 
  android:state_selected="true" 
  android:state_pressed="false" 
  android:drawable="@drawable/tab_focus"/> 
<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"/> 
<item android:state_pressed="true" 
      android:drawable="@drawable/tab_press"/> 
</selector>
HappyGeisha
Ok Thnx, so I make for each tab thats pressed focused and selected an image(.png) and give them an drawable resource.. is that the right way? Thnx!
anddevelop
For now, try to add all the android:state to the <item> tags in your custom_tab.xml file. Then use the <shape> and whatever else you already had and ignore the android:drawable. In my example, the drawable file is a .xml file defining tab style, such as the <shape>, <gradient> and <stroke> you used.
HappyGeisha