TabHost
来源:互联网 发布:python统计字母个数 编辑:程序博客网 时间:2024/05/01 07:38
方式一:继承TabActivity
public class MainActivity extends TabActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost=getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("TAB 1").setContent(R.id.textview1));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("TAB 2").setContent(R.id.textview2));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("TAB 3").setContent(R.id.textview3));
xml文件:
这三行是固定写法
android:id="@android:id/tabhost"
android:id="@android:id/tabs"
android:id="@android:id/tabcontent"
<TabHost
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:id="@android:id/tabhost"
tools:context="com.example.mytab.MainActivity" >
<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="wrap_content"
>
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="this is content1"
/>
<TextView
android:id="@+id/textview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="this is content2"
/>
<TextView
android:id="@+id/textview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="this is content3"
/>
</FrameLayout>
</LinearLayout>
</TabHost>
方式二:继承Activity
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost=(TabHost) findViewById(R.id.mytab);
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("TAB 1").setContent(R.id.textview1));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("TAB 2").setContent(R.id.textview2));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("TAB 3").setContent(R.id.textview3));
xml文件为:
android:id="@+id/mytab" (这个属性可以自定义)
android:id="@android:id/tabs"
android:id="@android:id/tabcontent"
<TabHost
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:id="@+id/mytab"
tools:context="com.example.mytab.MainActivity" >
<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="wrap_content"
>
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="this is content1"
/>
<TextView
android:id="@+id/textview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="this is content2"
/>
<TextView
android:id="@+id/textview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="this is content3"
/>
</FrameLayout>
</LinearLayout>
</TabHost>
- TabHost
- tabhost
- Tabhost
- TabHost
- tabHost
- TabHost
- TabHost
- tabhost
- Tabhost
- TabHost
- TabHost
- TabHost
- TabHost
- TabHost
- TabHost
- TabHost
- TabHost
- TabHost
- RxJava concat符操作处理多数据源
- Java 序列化Serializable详解(附详细例子)
- 基本算法之一——直接插入排序
- 怎么用maven创建一个Java Web项目?
- PHP 浏览器禁用cookie,解决session变量不能传值
- TabHost
- Scroller的使用,让View随心所欲的移动
- HTML5多媒体audio和video(一)
- android UI TextView setText显示服务器返回数据
- RAM,ROM和Flash memory等存储器的比较
- 求连续子数组的最大和
- Wine虚拟技术及其使用
- JSON
- IOS-TextField详解