From 8e4edb2862e9ae6c9a3e4936b70bb085a141cafc Mon Sep 17 00:00:00 2001
From: Tom O'Neill Notice that this doesn't use a layout file. Just create a {@link
android.widget.TextView}, give it some text and set that as the content. Duplicate this for
-each of the three activities.<activity/> tags to the Android Manifest file.
-
-
+
+
Copy these images for use in this tutorial. Save them into your project
-res/drawable/ directory. You now need to create a {@link
-android.graphics.drawable.Drawable} with XML that specifies which image
-to use for each state. Create a new file in res/drawable/ named
-ic_tab_artists.xml and insert the following:
For this tutorial, you can copy these images and use them for all three tabs. (When you +create tabs in your own application, you should create customized tab icons.)
+Now create a state-list drawable +that specifies which image to use for each tab state:
+res/drawable/ directory.res/drawable/
+named ic_tab_artists.xml and insert the following:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
@@ -62,9 +68,13 @@ to use for each state. Create a new file in res/drawable/ named
<item android:drawable="@drawable/ic_tab_artists_white" />
</selector>
- This is an XML definition for a {@link android.graphics.drawable.Drawable}, which you will -reference as the image for a tab. When the image state changes, the image will automatically -switch between the images defined here.
+This is a state-list drawable, +which you will apply as the tab image. When the tab state changes, the tab icon will +automatically switch between the images defined here.
+res/layout/main.xml file and insert the following:
@@ -86,7 +96,7 @@ switch between the images defined here.
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android;padding="5dp" />
+ android:padding="5dp" />
</LinearLayout>
</TabHost>
@@ -136,7 +146,7 @@ public void onCreate(Bundle savedInstanceState) {
spec = tabHost.newTabSpec("albums").setIndicator("Albums",
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(intent);
- mTabHost.addTab(spec);
+ tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs",
@@ -144,7 +154,7 @@ public void onCreate(Bundle savedInstanceState) {
.setContent(intent);
tabHost.addTab(spec);
- tabHost.setCurrentTab(getIntent());
+ tabHost.setCurrentTab(2);
}
This sets up each tab with their text and icon, and assigns each one an {@link @@ -157,7 +167,7 @@ android.widget.TabHost.TabSpec} identified by the given string tag. For each {@link android.widget.TabHost.TabSpec}, {@link android.widget.TabHost.TabSpec#setIndicator(CharSequence,Drawable)} is called to set the text and icon for the tab, and {@link android.widget.TabHost.TabSpec#setContent(Intent)} is called to specify -the {@link android.content.Intent} to opens the appropriate {@link android.app.Activity}. Each +the {@link android.content.Intent} to open the appropriate {@link android.app.Activity}. Each {@link android.widget.TabHost.TabSpec} is then added to the {@link android.widget.TabHost} by calling {@link android.widget.TabHost#addTab(TabHost.TabSpec)}.
@@ -187,7 +197,7 @@ calling {@link android.widget.TabHost#addTab(TabHost.TabSpec)}. -Your application should look like this:
+Your application should look like this (though your icons may be different):