From 8e4edb2862e9ae6c9a3e4936b70bb085a141cafc Mon Sep 17 00:00:00 2001 From: Tom O'Neill Date: Wed, 14 Apr 2010 09:36:37 -0700 Subject: cherry-pick from master: c096a9aead60717fc106ceb259bf954a578d3c54 (plus other revisions to resolve bug 2595831) Minor fixes in hello-tabwidget.jd Fix some typos, including a few that lead to non-functioning code. Change-Id: I0057ec7d54836b38d2c7f7b12617327d911f0915 --- .../resources/tutorials/views/hello-tabwidget.jd | 52 +++++++++++++--------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'docs/html/resources') diff --git a/docs/html/resources/tutorials/views/hello-tabwidget.jd b/docs/html/resources/tutorials/views/hello-tabwidget.jd index 199ceef..9bafd84 100644 --- a/docs/html/resources/tutorials/views/hello-tabwidget.jd +++ b/docs/html/resources/tutorials/views/hello-tabwidget.jd @@ -37,21 +37,27 @@ public class ArtistsActivity extends Activity {

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.

- -
  • You're going to need an icon for each of your tabs. And for each one, you should create an -image for two different states: one for when the tab is selected, and one for when it is not. The -general design recommendation is for the selected tab icon to be a darker color (grey), and the -non-selected icon to be lighter (white). For example: +each of the three activities, and add the corresponding <activity/> tags to the Android Manifest file.

    + +
  • You need an icon for each of your tabs. For each icon, you should create two versions: one +for when the tab is selected and one for when it is unselected. The +general design recommendation is for the selected icon to be a dark color (grey), and the +unselected icon to be a light color (white). (See the Icon Design +Guidelines.) For example:

    - - + +

    -

    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:

    +
      +
    1. Save the icon images in your project res/drawable/ directory.
    2. +
    3. Create a new XML file in 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.

      +
    4. +
    +
  • Open the 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):

    References

    -- cgit v1.1