Android(安卓)TabHost的使用(一)
16lz
2021-01-24
1. 最简单的TabHost,Tab来自于layout下的元素 (只从1个Layout中取数据)
(1)效果图
(2)代码
1)tab_demo.xml
[xhtml] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView android:id="@+id/tab_demo_tv1"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:text="tab_demo_tv1"
- />
- <TextView android:id="@+id/tab_demo_tv2"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:text="tab_demo_tv2"
- />
- <TextView android:id="@+id/tab_demo_tv3"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:text="tab_demo_tv3"
- />
- FrameLayout>
2)TabDemo.java
[java] view plain copy
- public class TabDemo extends TabActivity {
- private TabHost tabHost;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- tabHost = getTabHost();
- LayoutInflater.from(this).inflate(R.layout.tab_demo, tabHost.getTabContentView(), true);
- tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1", null).setContent(R.id.tab_demo_tv1));
- tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab2", null).setContent(R.id.tab_demo_tv2));
- tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Tab3", null).setContent(R.id.tab_demo_tv3));
- setContentView(tabHost);
- }
- }
更多相关文章
- Android(安卓)在 Fragment 中集成 React-Native(RN)步骤
- Android(安卓)DEX反编译后部分代码解析
- android ButterKnife 解决重复findViewById
- android解决中文乱码的所有方案
- 修改ExpandableListView前面展开小图标
- Android学习日记(1)
- 【Android】Android开源项目分类汇总
- Android测试,Android(安卓)Studio中的单元测试、UI测试和自动化测
- android中-----JSON例子一、 二