À´Ô´ : ×÷Õß : adminʱ¼ä : 2014-03-15 11:04:55 ÈËÆøÖ¸Êý :
Ê¢·ÅTabµÄÈÝÆ÷¾ÍÊÇTabHost
ÈçºÎʵÏÖ£¿£¿
ÿһ¸öTab»¹¶ÔÓ¦ÁËÒ»¸ö²¼¾Ö£¬Õâ¸ö¾ÍÓеãºÃÍæÁË¡£Ò»¸öActivity£¬¶ÔÓ¦Á˶à¸ö¹¦Äܲ¼¾Ö¡£
¢Ùн¨Ò»¸öTabÏîÄ¿£¬×¢Ò⣬²»ÒªÉú³Émain Activity
ÕâÀﲻҪѡ
¢ÚÔÚ°üÀïÃæн¨Ò»¸öÀàMyTab£¬¼Ì³ÐÓÚTabActivity
Æäʵ£¬TabActivityÊÇActivityµÄ×ÓÀà
- <FONT face=΢ÈíÑźÚ>package zyf.tab.test;
-
- import android.app.TabActivity;
-
- public class MyTab extends TabActivity {
-
- }</FONT>
¸´ÖÆ´úÂë
¢Û´Ó¸¸Àà¼Ì³ÐOnCreate()Èë¿Ú·½·¨
- <FONT face=΢ÈíÑźÚ>package zyf.tab.test;
- import android.app.TabActivity;
- import android.os.Bundle;
- public class MyTab extends TabActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- }
- }
- </FONT>
¸´ÖÆ´úÂë
¢ÜÔÚManifest.xmlÎļþÖÐ×¢²áÒ»ÏÂMyTabÀࣨActivity£©
- <FONT face=΢ÈíÑźÚ><activity android:name=".MyTab">
- <intent-filter>
- <action android:name="android.intent.action.MAIN"></action>
- <category android:name="android.intent.category.LAUNCHER"></category>
- </intent-filter>
- </activity></FONT>
¸´ÖÆ´úÂë
¢ÝÕâʱºò£¬ÐèÒªÉè¼ÆһϱêÇ©Ò³¶ÔÓ¦µÄ²¼¾Ö£¬Ò»°ã²ÉÓÃFrameLayout×÷Ϊ¸ù²¼¾Ö£¬Ã¿¸ö±êÇ©Ò³Ãæ¶ÔÓ¦Ò»¸ö×Ó½ÚµãµÄLayout
- <FONT face=΢ÈíÑźÚ><?xml version="1.0" encoding="utf-8"?>
- <!-- ÕâÀïÊǸù½Úµã²¼¾Ö -- >
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="fill_parent">
-
- <!-- µÚÒ»¸öTab ¶ÔÓ¦µÄ²¼¾Ö -- >
- <LinearLayout android:id="@+id/widget_layout_Blue"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- androidrientation="vertical" >
- <EditText android:id="@+id/widget34" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:text="EditText"
- android:textSize="18sp">
- </EditText>
- <Button android:id="@+id/widget30" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:text="Button">
- </Button>
- </LinearLayout>
- <!-- µÚ¶þ¸öTab ¶ÔÓ¦µÄ²¼¾Ö -- >
- <LinearLayout android:id="@+id/widget_layout_red"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- androidrientation="vertical" >
- <AnalogClock android:id="@+id/widget36"
- android:layout_width="wrap_content" android:layout_height="wrap_content">
- </AnalogClock>
- </LinearLayout>
- <!-- µÚÈý¸öTab ¶ÔÓ¦µÄ²¼¾Ö -- >
- <LinearLayout android:id="@+id/widget_layout_green"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- androidrientation="vertical">
- <RadioGroup android:id="@+id/widget43"
- android:layout_width="166px" android:layout_height="98px"
- androidrientation="vertical">
- <RadioButton android:id="@+id/widget44"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:text="RadioButton">
- </RadioButton>
- <RadioButton android:id="@+id/widget45"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:text="RadioButton">
- </RadioButton>
- </RadioGroup>
- </LinearLayout>
- </FrameLayout>
- </FONT>
¸´ÖÆ´úÂë
¢ÞÊ×ÏÈ£¬Ó¦¸ÃÉùÃ÷TabHost£¬È»ºóÓÃLayoutInflater¹ýÂ˳ö²¼¾ÖÀ´£¬¸øTabHost¼ÓÉϺ¬ÓÐTabÒ³ÃæµÄFrameLayout
- <FONT face=΢ÈíÑźÚ>private TabHost myTabhost;
- myTabhost=this.getTabHost();//´ÓTabActivityÉÏÃæ»ñÈ¡·ÅÖÃTabµÄTabHost
- LayoutInflater.from(this).inflate(R.layout.main, myTabhost.getTabContentView(), true);
- //from(this)´ÓÕâ¸öTabActivity»ñÈ¡LayoutInflater
- //R.layout.main ´æ·ÅTab²¼¾Ö
- //ͨ¹ýTabHost»ñµÃ´æ·ÅTab±êÇ©Ò³ÄÚÈݵÄFrameLayout
- //ÊÇ·ñ½«inflate ˩ϵµ½¸ù²¼¾ÖÔªËØÉÏ
- myTabhost.setBackgroundColor(Color.argb(150, 22, 70, 150));
- //ÉèÖÃÒ»ÏÂTabHostµÄÑÕÉ«
- </FONT>
¸´ÖÆ´úÂë
¢ß½Ó×Å£¬ÔÚTabHost´´½¨Ò»¸ö±êÇ©£¬È»ºóÉèÖÃһϱêÌ⣯ͼ±ê£¯±êÇ©Ò³²¼¾Ö
- <FONT face=΢ÈíÑźÚ>myTabhost
- .addTab(myTabhost.newTabSpec("TT")// ÖÆÔìÒ»¸öеıêÇ©TT
- .setIndicator("KK",
- getResources().getDrawable(R.drawable.ajjc))
- // ÉèÖÃÒ»ÏÂÏÔʾµÄ±êÌâΪKK£¬ÉèÖÃһϱêǩͼ±êΪajjc
- .setContent(R.id.widget_layout_red));
- //ÉèÖÃһϸñêÇ©Ò³µÄ²¼¾ÖÄÚÈÝΪR.id.widget_layout_red£¬ÕâÊÇFrameLayoutÖеÄÒ»¸ö×ÓLayout</FONT>
¸´ÖÆ´úÂë
¢à±êÇ©Çл»Ê¼þ´¦Àí£¬setOnTabChangedListener
- <FONT face=΢ÈíÑźÚ>myTabhost.setOnTabChangedListener(new OnTabChangeListener(){
- @Override
- public void onTabChanged(String tabId) {
- // TODO Auto-generated method stub
- }
- });</FONT>
¸´ÖÆ´úÂë
¢á¸÷¸ö±êÇ©Ò³µÄ¶¯Ì¬MENU
ÏÈ°ÑÔÚXMLÖÐÉè¼ÆºÃµÄMENU·Åµ½Ò»¸öintÊý×éÀï
- <FONT face=΢ÈíÑźÚ>private static final int myMenuResources[] = { R.menu.phonebook_menu,
- R.menu.addphone_menu, R.menu.chatting_menu, R.menu.userapp_menu };</FONT>
¸´ÖÆ´úÂë
ÔÚsetOnTabChangedListener()·½·¨Öиù¾Ý±êÇ©µÄÇл»Çé¿öÀ´ÉèÖÃmyMenuSettingTag
- <FONT face=΢ÈíÑźÚ>@Override
- public void onTabChanged(String tagString) {
- // TODO Auto-generated method stub
- if (tagString.equals("One")) {
- myMenuSettingTag = 1;
- }
- if (tagString.equals("Two")) {
- myMenuSettingTag = 2;
- }
- if (tagString.equals("Three")) {
- myMenuSettingTag = 3;
- }
- if (tagString.equals("Four")) {
- myMenuSettingTag = 4;
- }
- if (myMenu != null) {
- onCreateOptionsMenu(myMenu);
- }
- }</FONT>
¸´ÖÆ´úÂë
È»ºóonCreateOptionsMenu(Menu menu) ·½·¨ÖÐͨ¹ýMenuInflater¹ýÂËÆ÷¶¯Ì¬¼ÓÈëMENU
- <FONT face=΢ÈíÑźÚ> @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // TODO Auto-generated method stub
- // Hold on to this
- myMenu = menu;
- myMenu.clear();//Çå¿ÕMENU²Ëµ¥
- // Inflate the currently selected menu XML resource.
- MenuInflater inflater = getMenuInflater();
- //´ÓTabActivityÕâÀï»ñÈ¡Ò»¸öMENU¹ýÂËÆ÷
- switch (myMenuSettingTag) {
- case 1:
- inflater.inflate(myMenuResources[0], menu);
- //¶¯Ì¬¼ÓÈëÊý×éÖжÔÓ¦µÄXML MENU²Ëµ¥
- break;
- case 2:
- inflater.inflate(myMenuResources[1], menu);
- break;
- case 3:
- inflater.inflate(myMenuResources[2], menu);
- break;
- case 4:
- inflater.inflate(myMenuResources[3], menu);
- break;
- default:
- break;
- }
- return super.onCreateOptionsMenu(menu);
- }</FONT>
¸´ÖÆ´úÂë
http://www.aseoe.com/show-17-150-1.html http://www.aseoe.com/
true
AndroidµÄTabÓëTabHost½²½â
°®Ë¼×ÊÔ´Íø
http://www.aseoe.com/show-17-150-1.html
report
<£¿php echo strlen($content) / 2; ?>
Ê¢·ÅTabµÄÈÝÆ÷¾ÍÊÇTabHostÈçºÎʵÏÖ£¿£¿Ã¿Ò»¸öTab»¹¶ÔÓ¦ÁËÒ»¸ö²¼¾Ö£¬Õâ¸ö¾ÍÓеãºÃÍæÁË¡£Ò»¸öActivity£¬¶ÔÓ¦Á˶à¸ö¹¦Äܲ¼¾Ö¡£¢Ùн¨Ò»¸öTabÏîÄ¿£¬×¢Ò⣬²»ÒªÉú³Émain ActivityÕâÀﲻҪѡ¢ÚÔÚ°üÀïÃæн¨Ò»¸öÀàMyTa