0

To make the tabhost transparent i have implemented the following code..

    for(int i = 0; i < th.getTabWidget().getTabCount(); i++)
    {
    th.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
    }

This changes the background of all the tabs to transparent successfully in ICS but when I test it on 2.2 and 2.3 the first 3 tabs backgrounds are transparent and the last 3 are not(I have 6 tabs in all)(incidentally the 1st 3 tabs are the ones that appear when that activity gets started)

What is causing this and how can i resolve it... Please help..

After applying your suggestion this is what i included in the code,

        th.setOnTabChangedListener(new OnTabChangeListener(){
        @Override
        public void onTabChanged(String tabId) {
            manageTabBackgrounds();
        }

        private void manageTabBackgrounds() {
            // TODO Auto-generated method stub
            for(int i = 0; i < th.getTabWidget().getTabCount(); i++)
            {
            th.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
            }
        }           
    });

However this seems to have had no effect on the tabs... Please guide..

ark
  • 167
  • 1
  • 1
  • 14
  • I did check it.. On different devices. 1 running 2.3.5 and 1 running 4.0.3 and then i tested it on emulator – ark May 19 '12 at 06:34

3 Answers3

1

Make sure you do it onTabChanged...

Stick what you have in a function (e.g., "manageTabBackgrounds", then:

yourTabHostInstance.setOnTabChangedListener(new OnTabChangeListener(){
    @Override
    public void onTabChanged(String tabId) {
        manageTabBackgrounds();
    }           
});
momo
  • 3,885
  • 4
  • 33
  • 54
1

This is what finally worked for me..

  th.setOnTabChangedListener(new OnTabChangeListener(){
        @Override
        public void onTabChanged(String tabId) {
            // TODO Auto-generated method stub
             for(int i=0;i<th.getTabWidget().getChildCount();i++)
                {
                   th.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT); //unselected
                }
                th.getTabWidget().getChildAt(th.getCurrentTab()).setBackgroundColor(Color.TRANSPARENT); // selected
        }
        });
ark
  • 167
  • 1
  • 1
  • 14
0

Did you try this?

<TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent">
    </TabWidget>
Tai Tran
  • 1,406
  • 3
  • 15
  • 27
  • Yes.. but it wasn't giving me the result i was looking for.. Thanks for your efforts anyways..:) I answered the question with the code that was giving me the output I wanted.. – ark May 19 '12 at 14:20