Tabhost 运用详解
2012-09-03 15:08:53 来源:WEB开发网核心提示::id/tabs"android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>android:layout_height="wrap_
: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(
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(
更多精彩
赞助商链接