android选项卡TabHost功能怎么用
导读:本文共1903.5字符,通常情况下阅读需要6分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 首先定义三个xml文件,分别为l1.xml,l2.xml,l3.xml,每个选项卡的标签页的内容为一个xml文件。其中l1.xml为:<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.a... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。首先定义三个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);}}
效果如下图:
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:
android选项卡TabHost功能怎么用的详细内容,希望对您有所帮助,信息来源于网络。