1

i have working with tabs. i want to change the background color or theme for tab. when i click on the tab appears in default color as grey but i want to display that tab in custom color.

here my code:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"

     >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
               >

        >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-30dp"
            android:background="#FF0000"

            />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             >

        </FrameLayout>
    </LinearLayout>

</TabHost>

class file is

public class AndroidtabActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
//        View title = getWindow().findViewById(android.R.id.title);
//        View titleBar = (View) title.getParent();
//        titleBar.setBackgroundResource(R.drawable.top_bar2);


       Resources res = getResources();
        TabHost tabHost = getTabHost();
        //tabHost = (TabHost) findViewById(R.id.tabhost);
        tabHost.setup();
        //tabHost.setBackgroundResource(R.drawable.pink);


        TabHost.TabSpec spec; 
        //tabHost.getTabWidget().setDividerDrawable(R.drawable.top_bar);
        Intent in;
        in = new Intent().setClass(this, MainActivity.class);
        spec=tabHost.newTabSpec("calc").setIndicator("calculate").setContent(in);
        tabHost.addTab(spec);
        in = new Intent().setClass(this, TutorialZoomActivity1.class);
        spec=tabHost.newTabSpec("help").setIndicator("help").setContent(in);
        tabHost.addTab(spec);
        tabHost.setCurrentTab(2);
       // spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.flash));




    }
}

please tell me how can i change the background color for tabs.

NareshRavva
  • 823
  • 3
  • 21
  • 50

2 Answers2

0

You can change tab background color by

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
        tabHost.getTabWidget().getChildAt(i).
                                   setBackgroundResource(R.drawable.hans_layout_nblue);
    }
Azhar
  • 20,500
  • 38
  • 146
  • 211
0

Maybe you should create your custom tab.

  1. Let say.. create another custom_tab.xml (linearlayout and textview)
  2. in the linearlayout, set android:background to another xml file in the drawable (@drawable/tab_selector)
  3. Create new xml file in the drawable just mention above. ex. tab_selector.xml. in this file, you can set state (focused, pressed, selected etc)

    good luck
musefan
  • 47,875
  • 21
  • 135
  • 185
iJusran
  • 31
  • 1
  • 5