Reputation: 385
I have created 4 tabs in my application using tabHost , it working fine. below i show my code for adding only 2 tabs.
public class Home_tab extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_main);
Resources ressources = getResources();
TabHost tabHost = getTabHost();
// Android tab
Intent intentAndroid = new Intent().setClass(this, CoalActivity.class);
TabSpec tabSpecAndroid = tabHost
.newTabSpec("Android")
.setIndicator("", ressources.getDrawable(R.drawable.tab_dis))
.setContent(intentAndroid);
// Apple tab
Intent intentApple = new Intent().setClass(this, EnergyActivity.class);
TabSpec tabSpecApple = tabHost
.newTabSpec("Apple")
.setIndicator("", ressources.getDrawable(R.drawable.tab_foc))
.setContent(intentApple);
// add all tabs
tabHost.addTab(tabSpecAndroid);
tabHost.addTab(tabSpecApple);
}
}
This is my xml file
<?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="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:scrollbarAlwaysDrawHorizontalTrack="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
But my problem is when i add more tabs, it comes in the same window. for example, currently i added 4 tabs, when i try to add 3 more tabs , all the tabs are coming in the same window? i want to add only 4 tabs in the same window, other tabs should appears only when i scroll the tab bar How to solve this??
Upvotes: 2
Views: 2130
Reputation: 3313
Check following links and let me know if they helps in solving your problem
Upvotes: 1