I’m new to Android and i just created my first TabHost. Here’s the Code of the XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
style="@style/NormalFont"
android:text="@string/stats"
android:layout_weight="0.10"/>
<TabHost
android:id="@+id/TabHostStats"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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">
<ScrollView
android:id="@+id/ScrollViewSmileyFilter"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/TableLayoutSmileyFilter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*">
</TableLayout>
</ScrollView>
<ScrollView
android:id="@+id/ScrollViewADFilter"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/TableLayoutADFilter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*">
</TableLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
and here’s the code of the Activity:
public class StatsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stats);
TabHost host = (TabHost) findViewById(R.id.TabHostStats);
host.setup();
/** Dieser Code generiert den Tag für die Smileyfilter Stats**/
TabSpec SmileyFilterTab = host.newTabSpec("sftab");
SmileyFilterTab.setIndicator(getResources().getString(R.string.sfstats));
SmileyFilterTab.setContent(R.id.ScrollViewSmileyFilter);
host.addTab(SmileyFilterTab);
/**Dieser Code generiert den Tag für die Auto Delete Filter Stats **/
TabSpec AutoDeleteTab = host.newTabSpec("adtab");
AutoDeleteTab.setIndicator(getResources().getString(R.string.adstats));
AutoDeleteTab.setContent(R.id.ScrollViewADFilter);
host.addTab(AutoDeleteTab);
}
}
So the to registers of my TabHosts are on top. But I want them on the button, how can I do this? And also how and where can I change the Color of them. I want them unclicked in black and if they are clicked in blue.
i have seen many implementations. but this guys i like the most.
he has a tutorial and a downloadable sample project.
EDIT
after all these years the link seems to be broken. so here is the code.
here is an alternate link and just in case here is the code.
Images
TabsDemoActivity.java
main.xml
strings.xml
button_radio.xml
selected.xml
unselected.xml
EDIT
here is a couple of other links
android tabwidget
http://www.anddev.org/code-snippets-for-android-f33/iphone-tabs-for-android-t14678.html