简单的android选项卡Tab菜单TabHost(一)同一Activity上实现
来源:互联网 发布:钢琴教学软件 编辑:程序博客网 时间:2024/05/10 05:57
布局代码块activity_main.xml
<?xml version="1.0" encoding="UTF-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0.0dip" android:layout_weight="1.0" <Button android:id="@+id/superman" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="1" <Button android:id="@+id/spiderman" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="2" /> <Button android:id="@+id/batman" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="3" /> </FrameLayout> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" /> </LinearLayout> </TabHost>
说明:(1)代码中的标签里面是选项卡当前页面的内容,如下列案例中运行效果图中的图一。标签则是选项卡的选项模块,如下列案例中运行效果图中的图二。
(2)默认的选项卡模块一般是在整个界面的上面,但当设置标签里面的属性 android:layout_weight=”1.0” 的时候,选项卡模块就会自动布局在最底下如本案例。
注意:
TabHost的id必须定义为android:id=”@android:id/tabhost”,TabWidget的id必须定义为android:id=”@android:id/tabs”,FrameLayout的id必须定义为android:id=”@android:id/tabcontent”。
Activity代码块MainActivity.java
import android.os.Bundle;import android.app.TabActivity;import android.view.Menu;import android.widget.TabHost;import android.widget.TabHost.TabSpec;@SuppressWarnings("deprecation")public class MainActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TabHost tabHost = getTabHost(); TabSpec page1 = tabHost.newTabSpec("tab1") .setIndicator("超人", getResources().getDrawable(R.drawable.ic_launcher)) .setContent(R.id.superman); tabHost.addTab(page1); TabSpec page2 = tabHost.newTabSpec("tab2") .setIndicator("蜘蛛侠") .setContent(R.id.spiderman); tabHost.addTab(page2); TabSpec page3 = tabHost.newTabSpec("tab3") .setIndicator("蝙蝠侠") .setContent(R.id.batman); tabHost.addTab(page3); }}
运行效果如下:
图一
图二
运行效果图
源代码下载
TabMenu.jar
0 0
- 简单的android选项卡Tab菜单TabHost(一)同一Activity上实现
- [Tab选项卡菜单(一)]位于顶部的tab选项卡菜单
- TabHost选项卡的实现(一):使用TabActivity实现
- js实现tab菜单(选项卡)
- Android TabHost每个Tab的Activity事件
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(一)
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(一)
- Android之Tab分页标签的实现方法一----TabActivity和TabHost的结合(一)
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(一)
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(一)
- 实现一个简单的tab选项卡
- javascript实现简单的tab选项卡
- cocos2dx一tab选项卡的实现
- 【Android】FragmentTabHost实现底部Tab菜单选项
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(二)
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(三)
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(二)
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(三)
- Markdown学习笔记:如何画流程图
- Tomcat return http status error: 403, Reason Phrase: Forbidden:
- 什么是游戏开发的实体系统框架
- Swift-入门简介
- QAxObject操作Excel表格
- 简单的android选项卡Tab菜单TabHost(一)同一Activity上实现
- Perl的中国镜像网站--下载速度更快
- Qt5 上下文菜单的三种实现方式
- mac 下safari如何快速删除书签/收藏
- POJ Oulipo(KMP模板题)
- UVA 12487 Midnight Cowboy(LCA+大YY)(好题)
- 查看设备序列号和设备标识的方式(有三种方法)
- android 中在一个程序中启动另一个程序的三种方式
- ubuntu12.04 WPS等软件无法输入中文解决