1./TestTabWidget/res/layout/main.xml:
<? xml   version="1.0" encoding="utf-8"?>

<TabHostxmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@android:id/tabhost"

    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_height="fill_parent"

    android:layout_width="fill_parent"

    >

    <TextView

    android:id="@+id/textview01"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:text="this is one tab!"

    />

    <TextView

    android:id="@+id/textview02"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:text="this is tow tab!"

    />

    <TextView

    android:id="@+id/textview03"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:text="this is third tab!"

    />

    FrameLayout>

    LinearLayout>

TabHost>

2.TestTabWidgetActivity:

import android.app.AlertDialog;

import android.app.Dialog;

import android.app.TabActivity;

import android.content.DialogInterface;

import android.content.DialogInterface.OnClickListener;

import android.graphics.Color;

import android.os.Bundle;

import android.widget.TabHost;

import android.widget.TabHost.OnTabChangeListener;

 

public class TestTabWidgetActivity extends TabActivity

{

    private TabHost mTabHost;

 

    @Override

    public void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        // 取得TabHost对象

        mTabHost = getTabHost();

        // TabHost添加标签

        mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1",

               getResources().getDrawable(R.drawable.flag)).setContent(R.id.textview01));

        mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2",

               getResources().getDrawable(R.drawable.flag2)).setContent(R.id.textview02));

        mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3",

               getResources().getDrawable(R.drawable.flag3)).setContent(R.id.textview03));

        // 设置TabHost背景颜色

        // mTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));

        // 设置TabHost的背景图片资源

        // mTabHost.setBackgroundResource(R.drawable.icon);

        // 设置当前显示哪一个标签setOnTabChangedListener

        mTabHost.setCurrentTab(0);

        // 标签处理事件

        mTabHost.setOnTabChangedListener(new OnTabChangeListener()

        {

            @Override

            public void onTabChanged(String tabId)

            {

                Dialog dialog = newAlertDialog.Builder(TestTabWidgetActivity.this).setTitle("提示").setMessage(

                        "当前选择的是" + tabId + "号标签").setPositiveButton("确定", newOnClickListener()

                {

                    @Override

                    public voidonClick(DialogInterface dialog, int which)

                    {

                        dialog.cancel();

                    }

                }).create();// 创建按钮

                dialog.show();

            }

        });

 3.效果图:

软件运行:


选择其中的一个标签,出现一个dialog提示框:

更多相关文章

  1. Android(安卓)ProgressDialog的使用
  2. Android为Notification加上一个进度条
  3. Android(安卓)setTag和getTag()的使用
  4. Android设置全屏的两种方法
  5. android 基础知识
  6. android maxLines ellipsize 配合使用失效,解决办法
  7. MpAndroidChart简单用法 属性总结
  8. Android之检查网络是否可用(跳转网络设置页面)
  9. android 录音

随机推荐

  1. Android(安卓)强制横屏
  2. android中去掉button的边框和EditText中
  3. Android(安卓)各种工具类 图片下载工具类
  4. 【Arcgis for android】Error inflating
  5. Android(安卓)获取 IP 地址
  6. Android以TelephonyManager取得話機狀態
  7. Android各版本占比信息统计
  8. android 拖动图片移动效果
  9. android输入法控制显示
  10. android异步操作AsyncTask编写文件查看器