TabHost简单的代码实现
来源:互联网 发布:淘宝的读书软件 编辑:程序博客网 时间:2024/05/16 08:59
下面给大家带来一个TabHost的简单实现
in.xml
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabhost" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs" ></TabWidget> <FrameLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:id="@android:id/tabcontent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/widget_layout_red" android:background="#ff0000" android:orientation="vertical" ></LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/widget_layout_yellow" android:background="#FCD209" android:orientation="vertical" ></LinearLayout> </FrameLayout></LinearLayout></TabHost>
继承TabActivity (方法一)
public class MainActivity extends TabActivity {private TabHost tabhost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.demo); //从TabActivity上面获取放置Tab的TabHost tabhost = getTabHost(); tabhost.addTab(tabhost //创建新标签one .newTabSpec("one") //设置标签标题 .setIndicator("红色") //设置该标签的布局内容 .setContent(R.id.widget_layout_red)); tabhost.addTab(tabhost.newTabSpec("two").setIndicator("黄色").setContent(R.id.widget_layout_yellow)); }}
方法二:继承Activity类
public class MainActivity extends Activity{private TabHost tabhost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.demo); //得到TabHost对象实例 tabhost =(TabHost) findViewById(R.id.mytab); //调用 TabHost.setup() tabhost.setup(); //创建Tab标签 tabhost.addTab(tabhost.newTabSpec("one").setIndicator("红色").setContent(R.id.widget_layout_red)); tabhost.addTab(tabhost.newTabSpec("two").setIndicator("黄色").setContent(R.id.widget_layout_yellow)); }}
以上代码就是本篇文章所描述代码.
希望能帮助到需要帮助的人.
阅读全文
0 0
- TabHost简单的代码实现
- tabhost实现计数标签的简单用法
- TabHost配合fragment的简单框架实现
- 纯代码实现TabHost
- 简单的TabHost
- Tabhost的简单使用
- tabHost的简单使用
- Tabhost的简单运用
- Tabhost的简单使用
- Tabhost的简单用法
- TabHost的简单实用
- 实现美观的TabHost
- TabHost的底部实现
- TabHost的实现
- TabHost TabWidget的简单用法
- android 简单tabHost的用法
- TabHost空间的简单使用
- Android TabHost实现简单标签页
- java 泛型
- 最简单的 TensorFlow 代码,TensorFlow Hello World 。
- ORACLE物化视图
- 关于Java中值传递还是引用传递的问题解析-------引用校招笔试中的一道题进行解释
- [BZOJ1512][VijosP1006]晴天小猪历险记
- TabHost简单的代码实现
- angular2依赖注入概述
- 遇到问题---MongoDB--$not和$and搭配使用报错---operator $not is not allowed around criteria chain element: { "$an
- JMeter基础之—录制脚本
- toad10.5启动报错(Can't initialize OCI. Error -1)
- (79)Arrays工具类:集合或者普通数组的操作方法、集合和数组相互转换
- tcp ip 通信socket
- js数据类型
- Tips:解决问题“error LNK2026: 模块对于 SAFESEH 映像是不安全的。”