android studio tabhost基础 多功能时钟app tabhost
2016-07-23 17:43
453 查看
新建项目,在layout中添加tabhost组件:
在mainactivity中写入代码:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.example.jowang.clock.MainActivity"> <TabHost android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tabHost" android:layout_gravity="center_horizontal"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content"></TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/tabTime" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"></LinearLayout> <LinearLayout android:id="@+id/tabAlarm" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"></LinearLayout> <LinearLayout android:id="@+id/tabTimer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"></LinearLayout> <LinearLayout android:id="@+id/tabStopwatch" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"></LinearLayout> </FrameLayout> </LinearLayout> </TabHost> </LinearLayout>
在mainactivity中写入代码:
public class MainActivity extends AppCompatActivity { private TabHost tabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tabHost=(TabHost)findViewById(R.id.tabHost); tabHost.setup(); tabHost.addTab(tabHost.newTabSpec("tabTime").setIndicator("时钟").setContent(R.id.tabTime)); tabHost.addTab(tabHost.newTabSpec("tabAlarm").setIndicator("闹钟").setContent(R.id.tabAlarm)); tabHost.addTab(tabHost.newTabSpec("tabTimer").setIndicator("计时器").setContent(R.id.tabTimer)); tabHost.addTab(tabHost.newTabSpec("tabStopwatch").setIndicator("秒表").setContent(R.id.tabStopwatch)); } }
相关文章推荐
- Android学习之BottomNavigationBar实现Android特色底部导航栏
- Android调试工具
- AIDL在android系统中的作用
- Android群英传之Android动画机制与使用技巧
- Android短信验证+源码
- 从AIDL看Android跨进程通信
- Android系统应用调用Aidl
- Error处理: “非法字符: \65279”的解决办法
- 关于android的MeasureSpec的解读
- Android屏幕适配之支持各种屏幕密度(三)
- android NDK开发环境搭建(windows) 最新整理 截止2012年9月
- Android屏幕适配之布局设置(二)
- Android实现自定义字体格式液晶数字
- Android 屏幕适配之各种概念(一)
- Android常用开发工具类
- iOS应用文件夹
- 移动端爬坑记 --- (2)移动端访问设备判断(user-agent)及实现流程
- Android实现OCR扫描识别数字图片之图片扫描识别
- 移动端爬坑记 --- (2)移动端访问设备判断(user-agent)及实现流程
- Android官方数据绑定框架DataBinding