android选项卡TabHost功能怎么用(android,tabhost,开发技术)

时间:2024-05-03 15:44:18 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

首先定义三个xml文件,分别为l1.xml,l2.xml,l3.xml,每个选项卡的标签页的内容为一个xml文件。

其中l1.xml为:

<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:id="@+id/l1"><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button"/></LinearLayout>

l2.xml为:

<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:id="@+id/l2"><EditTextandroid:id="@+id/editText1"android:layout_width="match_parent"android:layout_height="wrap_content"android:ems="10"android:inputType="textPersonName"><requestFocus/></EditText><EditTextandroid:id="@+id/editText2"android:layout_width="match_parent"android:layout_height="wrap_content"android:ems="10"android:inputType="textPassword"/></LinearLayout>

l3.xml为:

<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:id="@+id/l3"><RatingBarandroid:id="@+id/ratingBar1"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout>

TabActivityDemo2.java:

packagecom.example.wenandroid;importandroid.app.TabActivity;importandroid.os.Bundle;importandroid.view.LayoutInflater;importandroid.widget.TabHost.TabSpec;publicclassTabActivityDemo2extendsTabActivity{protectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);android.widget.TabHosttab=getTabHost();LayoutInflaterlay=LayoutInflater.from(this);lay.inflate(R.layout.l1,tab.getTabContentView(),true);lay.inflate(R.layout.l2,tab.getTabContentView(),true);lay.inflate(R.layout.l3,tab.getTabContentView(),true);TabSpect1=tab.newTabSpec("t1");TabSpect2=tab.newTabSpec("t2");TabSpect3=tab.newTabSpec("t3");t1.setIndicator("选项卡1");t2.setIndicator("选项卡2");t3.setIndicator("选项卡3");t1.setContent(R.id.l1);t2.setContent(R.id.l2);t3.setContent(R.id.l3);tab.addTab(t1);tab.addTab(t2);tab.addTab(t3);}}

效果如下图:

android选项卡TabHost功能怎么用

android选项卡TabHost功能怎么用

android选项卡TabHost功能怎么用

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:android选项卡TabHost功能怎么用的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:C++引用怎么使用及底层原理是什么下一篇:

5 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18