这篇文章主要为大家详细介绍了android选项卡TabHost的功能用法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了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功能用法详解
猜你喜欢
- Flutter实现底部和顶部导航栏 2022-08-31
- 详解flutter engine 那些没被释放的东西 2022-12-04
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- Android实现监听音量的变化 2023-03-30
- Android实现轮询的三种方式 2023-02-17
- iOS 对当前webView进行截屏的方法 2023-03-01
- Android studio实现动态背景页面 2023-05-23
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
