选项卡的使用方法一(Android学习随笔十二)
来源:互联网 发布:淘宝卖家需要什么软件 编辑:程序博客网 时间:2024/06/06 15:04
选项卡的使用方法一(Android学习随笔十二)
1、继承TabActivity;
2、用getTabHost()方法获取TabHost;
3、各Tab内容在布局文件中定义。
java代码:
package yc.demo;import android.app.TabActivity;import android.os.Bundle;import android.view.LayoutInflater;import android.widget.TabHost;import android.widget.TabHost.TabSpec;public class TabhostDemo2Activity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //获取到TabHost TabHost tabHost = this.getTabHost(); //把我们的布局文件添加到tabHost的FrameLayout下面 LayoutInflater.from(this).inflate(R.layout.demo2, tabHost.getTabContentView(), true); //获取一个新的TabHost.TabSpec,并关联到当前tabHost //参数:所需的选项卡标签 TabSpec pSpes = tabHost.newTabSpec("parent"); pSpes.setIndicator("父类", this.getResources().getDrawable(R.drawable.msg_icon)); pSpes.setContent(R.id.tv1); TabSpec subSpec = tabHost.newTabSpec("sub"); subSpec.setIndicator("子类",this.getResources().getDrawable(R.drawable.at_icon)); subSpec.setContent(R.id.tv2); //向tabHost中添加选项卡 tabHost.addTab(subSpec); tabHost.addTab(pSpes); }}
xml布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/tab1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/tv1" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="parent"/> </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/tv2" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="sub"/> </LinearLayout></LinearLayout>
- 选项卡的使用方法一(Android学习随笔十二)
- 选项卡使用方法二(Android学习随笔十三)
- android 学习随笔二十二(小结)
- android 学习随笔十二(网络:使用异步HttpClient框架)
- android 项目学习随笔十二(ListView加脚布局)
- android TabHost(选项卡)的使用方法发布
- android TabHost(选项卡)的使用方法
- android TabHost(选项卡)的使用方法
- Android学习之随笔(一)
- android 项目学习随笔一(闪屏 )
- ExtJS4学习笔记(十二)---选项卡(tabs)
- Linux学习笔记(十二、选项帮助)
- android学习-----使用TabLayout实现Tab选项卡以及遇到的一些问题(一)
- javascript系统学习的随笔(一)
- 随笔(十二)
- Android Handler使用方法(一) 学习笔记
- opengl 入门学习 随笔十二
- U2TP学习随笔(一)
- asp.net 中遍历页面里某种控件(Textbox)、获取当前页面的名称
- 如何学好算法与程序设计
- 专业任选课“面向对象程序设计”期末作业1——成绩统计
- Window7创建wifi
- onresize事件
- 选项卡的使用方法一(Android学习随笔十二)
- 语记
- 初学Qt 登陆对话框
- 过滤器的实现(清除缓存)
- 网络连接慢,设置ip过程中碰到的问题
- 文件下载
- Hash学习(2)-Hash函数
- oracle性能优化
- Filter(过滤器)简介