Question

StyleMe

Here is an image. i want tabview image background like this.When it is not selected it shows white image and when it is selected it shows green image.

Here is the code:

Resources resources = getResources();
TabHost tabhost = getTabHost();
Intent one = new Intent().setClass(this, StyleMe.class);
TabSpec tb1=tabhost.newTabSpec("One").setIndicator("",resources.getDrawable
(R.drawable.style_link)).setContent(one); 
tabhost.addTab(tb1);
Was it helpful?

Solution

The better solution is to use background with selector, so you don't have to check onTabChanged and do manual update.:

private void initTabsAppearance(TabWidget tabWidget) {
    // Change background
    for(int i=0; i < tabWidget.getChildCount(); i++)
        tabWidget.getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
}

Where tab_bg is an xml drawable with selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">    
    <item android:state_selected="true" android:drawable="@drawable/tab_bg_selected" />
    <item android:drawable="@drawable/tab_bg_normal" />
</selector>

Hope this will help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top