views:

203

answers:

1

Hi All,

I was wondering... how can I change the tab colors when selected and when deselected. Here's a picture of how it looks now:

http:// i.imgur.com/FOT4Q.jpg

I would like my tabinterface will look like this:

http:// www.technobuzz.net/wp-content/uploads/2010/02/seesmic-android-260-208.png

So i can't change my colors of the tabs... I think this is a sense issue. I hope someone can try to help...all responses / solutions are welcomed. I've tried many options but no effect here is my source code:

Main.java

// Create a tab

intent = new Intent().setClass(this, Home.class);        
spec = tabHost.newTabSpec("home").setIndicator("Home",
         res.getDrawable(R.drawable.tab_home))
            .setContent(intent);
         tabHost.addTab(spec);

tab_home.xml

    <?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:background="@drawable/custom_tab"
          />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/artists_of" />
</selector>

custom_tab.xml

   <selector
    xmlns:android="http://schemas.android.com/apk/res/android"&gt;

    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="#0000ff"
                android:endColor="#000000"
                android:angle="270" />
            <stroke
                android:width="3dp"
                android:color="#2e2e2e" />
            <corners
                android:radius="3dp" />

        </shape>
    </item>

    <item android:state_focused="true" >
        <shape>
            <gradient
                android:endColor="#802222"
                android:startColor="#B02222"
                android:angle="270" />
            <stroke
                android:width="3dp"
                android:color="#2e2e2e" />
            <corners
                android:radius="3dp" />

        </shape>
    </item>

    <item>        
        <shape>

           <gradient
                android:startColor="#999999"
                android:centerColor="#555555"
                android:endColor="#999999"
                android:height="1px"
                android:angle="0" />
            <stroke
                android:width="3dp"
                android:color="#2e2e2e" />
            <corners
                android:radius="3dp" />

        </shape>
    </item>
</selector>

Thanks!

A: 

Does this help?

Or this??

From what I understand, this is what you're looking for:

TabWidget tw = getTabWidget(); 
for (int i = 0; i < tw.getChildCount(); i++) { 
        View v = tw.getChildAt(i); 
        v.setBackgroundDrawable(getResources().getDrawable 
(R.drawable.custom_tab)); 
      } 
HappyGeisha
Thanks this works now I have an another problem :-( http://stackoverflow.com/questions/3917168/android-change-tab-colors-tabwidget
anddevelop
Glad I could help! Could you mark my response as the correct answer by clicking on the check mark?
HappyGeisha