D.K.的Android旅程----TabHost

       很长时间没写博客了,前段时间因为忙于考试,加上自己的惰性,博客就忘写了,今天自己补上一篇。

       今天补上的这篇是关于TabHost。虽然TanHost现在已经被启用了,但不可否认的是,在很多情况下,大多数开发者还是喜欢这个组件的。

       与TabHost一起使用的还有如下组件:

       ·TabWidget:选项卡标签条

       ·TabSpec:选项卡的一个Tab界面

       TabHost是个容器,它提供了两种方式来创建或添加选项卡:

       ·newTabSpec(Stringtag):添加新选项卡

       ·addTab(TabHost, TabSpec tabSpec):添加新选项卡

 

       基本的介绍已经差不多了,现在上代码。

 

XML:

       <?xmlversion="1.0" encoding="utf-8"?>

<TabHost

   xmlns:android="http://schemas.android.com/apk/res/android"

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

   android:layout_width="match_parent"

    android:layout_height="match_parent">

   <RelativeLayout

       android:layout_width="fill_parent"

       android:layout_height="wrap_content"

       android:orientation="vertical">

       <TabWidget

           android:id="@android:id/tabs"

            android:layout_width="fill_parent"

           android:layout_height="wrap_content"

                     <!------------令选项卡处于屏幕下方--------------->

           android:layout_alignParentBottom="true"

            />

       <FrameLayout

           android:id="@android:id/tabcontent"

           android:layout_width="fill_parent"

           android:layout_height="fill_parent"

            >

           <LinearLayout

               android:id="@+id/tabs01"

               android:layout_width="fill_parent"

               android:layout_height="fill_parent"

               android:orientation="vertical"

                >

               <TextView

                   android:layout_width="fill_parent"

                   android:layout_height="wrap_content"

                   android:text="D.K."

                   android:textSize="18pt"/>

               <TextView

                   android:layout_width="fill_parent"

                   android:layout_height="wrap_content"

                   android:text="男"

                   android:textSize="18pt"/>

               <TextView

                    android:layout_width="fill_parent"

                   android:layout_height="wrap_content"

                   android:text="20"

                   android:textSize="18pt"/>

           </LinearLayout>

       </FrameLayout>

    </RelativeLayout>

</TabHost>

 

 

Java:

public class MainActivity extends TabActivity {

       NotificationManagernm ;

    @Override

    public voidonCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main) ;

        TabHosttabs = getTabHost() ;

        TabSpectab1 = tabs.newTabSpec("tab1").setIndicator("DK's info")

                 .setContent(R.id.tabs01);

       tabs.addTab(tab1) ;

       

        Intentintent = new Intent(MainActivity.this , NewClass.class) ;

        TabSpectab2 = tabs.newTabSpec("tab2").setIndicator("Notify")

.setContent(intent);       //想要选项卡显示复杂内容时,启动一个新的Activity会//更好,在这就不写出这个新的Activity了

       tabs.addTab(tab2);

 

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值