Question

Hi im trying to style my tabactivity im using this:

public class TabContainer extends TabActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tab_container);

    //TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
    TabHost tabHost = getTabHost();

    // Tab for Radio
    TabSpec radioTabSpec = tabHost.newTabSpec("Radio Online");
    // setting Title and Icon for the Tab
    radioTabSpec.setIndicator("Radio Online", getResources().getDrawable(R.drawable.menu_radio));
    Intent radioIntent = new Intent(this, MainActivity.class);
    radioTabSpec.setContent(radioIntent);

    // Tab for Facebook
    TabSpec facebookTabSpec = tabHost.newTabSpec("Facebook");
    facebookTabSpec.setIndicator("Facebook", getResources().getDrawable(R.drawable.menu_facebook));
    Intent facebookIntent = new Intent(this, FacebookActivity.class);
    facebookTabSpec.setContent(facebookIntent);

    // Tab for Twitter
    TabSpec twitterTabSpec = tabHost.newTabSpec("Twitter");
    twitterTabSpec.setIndicator("Twitter", getResources().getDrawable(R.drawable.menu_twitter));
    Intent twitterIntent = new Intent(this, TwitterActivity.class);
    twitterTabSpec.setContent(twitterIntent);

    // Tab for About
    TabSpec aboutTabSpec = tabHost.newTabSpec("Acerca");
    aboutTabSpec.setIndicator("Acerca", getResources().getDrawable(R.drawable.menu_about));
    Intent aboutIntent = new Intent(this, AboutActivity.class);
    aboutTabSpec.setContent(aboutIntent);
    // Adding all TabSpec to TabHost

    tabHost.addTab(radioTabSpec); // Adding photos tab
    tabHost.addTab(facebookTabSpec); // Adding songs tab
    tabHost.addTab(twitterTabSpec); // Adding videos tab
    tabHost.addTab(aboutTabSpec); // Adding videos tab
}

}

here is my xml:

  <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </LinearLayout>
</TabHost>

tabs style example:

enter image description here

i know tabactivity is old but i cant find any other way to make it work for android 2.3 and later now my tabs are showing totally black, i would like to style it to make it more nice.

thank you very much.

Was it helpful?

Solution

OTHER TIPS

FYI TabActivity is deprecated.

Instead, why don't you use ActionBar with tabs and to provide compatibility, you can use ActionBarSherlock.

What is ActionBarSherlock?

ActionBarSherlock is an extension of the support library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API.

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