Tabhost 运用详解
来源:互联网 发布:中央12网络电视台直播 编辑:程序博客网 时间:2024/05/22 12:58
------------------------------------------Tabhost布局
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
>
<LinearLayout android:id="@+id/LinearLayout01"
android:orientation="vertical" android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_height="fill_parent" android:layout_width="fill_parent"></FrameLayout>
</LinearLayout>
</TabHost>
--------------------------------------解释:
<TabWidget android:id="@android:id/tabs"
android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>
----android:layout_height="wrap_content" 需要是wrap_content属性.
--------------------------------.JAVA
package com.android.tab;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabBarExample extends TabActivity {
private int myMenuRes[] = {
R.drawable.tab1,
R.drawable.tab2,
R.drawable.tab3,
R.drawable.tab4,
R.drawable.tab5
};
TabHost tabHost;
TabSpec firstTabSpec;
TabSpec secondTabSpec;
TabSpec threeTabSpec;
TabSpec fourTabSpec;
TabSpec fiveTabSpec;
TabSpec six;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
setTitle("最後一堂課");
/* TabHost will have Tabs */
tabHost = (TabHost) findViewById(android.R.id.tabhost);
// tabHost.setBackgroundResource(R.drawable.nav_background);
/*
* TabSpec used to create a new tab. By using TabSpec only we can able
* to setContent to the tab. By using TabSpec setIndicator() we can set
* name to tab.
*/
/* tid1 is firstTabSpec Id. Its used to access outside. */
firstTabSpec = tabHost.newTabSpec("tid1");
secondTabSpec = tabHost.newTabSpec("tid2");
threeTabSpec = tabHost.newTabSpec("tid3");
fourTabSpec = tabHost.newTabSpec("tid4");
fiveTabSpec = tabHost.newTabSpec("tid5");
six=tabHost.newTabSpec("最後一次戰鬥");
/* TabSpec setIndicator() is used to set name for the tab. */
/* TabSpec setContent() is used to set content for a particular tab. */
six.setIndicator("finally",getResources().getDrawable(R.drawable.maket));
firstTabSpec.setIndicator("Latest", getResources().getDrawable(
myMenuRes[0]));
secondTabSpec.setIndicator("Topics", getResources().getDrawable(
myMenuRes[1]));
threeTabSpec.setIndicator("Video", getResources().getDrawable(
myMenuRes[2]));
fourTabSpec.setIndicator("Podcast", getResources().getDrawable(
myMenuRes[3]));
fiveTabSpec.setIndicator("Gallery", getResources().getDrawable(
myMenuRes[4]));
six.setContent(new Intent(this,FirstTab.class));
firstTabSpec.setContent(new Intent(this, FirstTab.class));
secondTabSpec.setContent(new Intent(this, SecondTab.class));
threeTabSpec.setContent(new Intent(this, FirstTab.class));
fourTabSpec.setContent(new Intent(this, SecondTab.class));
fiveTabSpec.setContent(new Intent(this, SecondTab.class));
/* Add tabSpec to the TabHost to display. */
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(threeTabSpec);
tabHost.addTab(fourTabSpec);
tabHost.addTab(fiveTabSpec);
tabHost.addTab(six);
}
}
- Tabhost 运用详解
- Tabhost的简单运用
- TabHost详解
- TabHost详解
- TabHost详解
- TabHost详解
- TabHost详解
- TabHost详解
- TabHost详解
- TabHost详解
- TabHost详解
- Android TabHost用法详解
- TabHost使用详解
- TabHost详解0
- Android TabHost用法详解
- tabhost入门详解
- Android TabHost用法详解
- Android之TabHost用法详解
- 那年,那场青春繁华梦
- 把握当下每个时刻
- qt实现点击输入框弹出输入面板和改变窗口的位置
- 归并排序:数组和单链表实现
- 14岁初中生—— 踏踏实实的人生也最美
- Tabhost 运用详解
- mvc json实现选择列表之后,发布功能
- Base64编码
- arcgis rest 学习笔记1
- curl抓取页面时遇到重定向的解决方法
- 心醉七夕
- 枸杞的功效与食用方法
- 更改手机窗口画面底色
- oracle体系架构