Android Tab-layout:
Android TabLayout |
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/trans">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/signup"
android:layout_alignParentBottom="true" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs" >
<LinearLayout
android:id="@+id/first"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/third"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</FrameLayout>
</RelativeLayout>
</TabHost>
JAVA Code
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class Tabactivity extends Activity {
TabHost tabHost;
TabSpec firstTab,secondTab,thirdTab;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabactivity);
tabHost = (TabHost)findViewById(R.id.tabhost);
tabHost.setup();
firstTab = tabHost.newTabSpec("First");
secondTab = tabHost.newTabSpec("Second");
thirdTab = tabHost.newTabSpec("Third");
firstTab.setIndicator("",getResources().getDrawable(R.drawable.home));
firstTab.setContent(R.id.first);
secondTab.setIndicator("",getResources().getDrawable(R.drawable.redicon));
secondTab.setContent(R.id.second);
thirdTab.setIndicator("",getResources().getDrawable(R.drawable.exit));
thirdTab.setContent(R.id.third);
tabHost.addTab(firstTab);
tabHost.addTab(secondTab);
tabHost.addTab(thirdTab);
}
}
No comments:
Post a Comment