27 SepCustomize tabs in Android

Monday, 27 September 2010 — 13:34

This is one the most repeated questions in Android, and here you will get a real answer of how it’s implemented.

        mTabHost = getTabHost();
            
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab
            
        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, FirstTab.class);
        
        //Add tab to mTabHost (repeat for each tab)
        spec = mTabHost.newTabSpec("first_tab");
                View indicator = View.inflate(this, R.layout.tab, null);
                TextView text = (TextView) indicator.findViewById(R.id.title);
                text.setText(getString(R.string.first_tab));
                spec.setIndicator(indicator);
                spec.setContent(intent);
                mTabHost.addTab(spec);

where the tab.xml is this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:gravity="center" 
        android:background="@drawable/tab_indicator">
        <TextView android:id="@+id/title" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:singleLine="true"
                android:ellipsize="marquee" android:textStyle="bold"
                android:textColor="@color/tab_text_color"/>
</LinearLayout> 

Ger

Comentarios

  1. Avatar Eby
    14 Dec 13:21

    Wow.. Great example..!!!
    Thank you

  2. Avatar eby
    22 Jan 11:17

    How can i identify different states in TAB

Añade tu comentario




(textile habilitado)
Negrita: *Google*
Enlace: "google.com":http://www.google.com
Imagen: !http://ggomeze.com/images/avatar.png!

ó Cancelar