本篇内容介绍了“android选项卡TabHost功能怎么用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
首先定义三个xml文件,分别为l1.xml,l2.xml,l3.xml,每个选项卡的标签页的内容为一个xml文件。
其中l1.xml为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
l2.xml为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
l3.xml为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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">
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
TabActivityDemo2.java:
package com.example.wenandroid;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost.TabSpec;
public class TabActivityDemo2 extends TabActivity {
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
android.widget.TabHost tab=getTabHost();
LayoutInflater lay=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);
TabSpec t1=tab.newTabSpec("t1");
TabSpec t2=tab.newTabSpec("t2");
TabSpec t3=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功能怎么用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。