要得到这样的界面:一个大的框架下有三个tab,tab之间可以切换
这是我的实现
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> </TabHost>
android:id="@android:id/tabhost"<pre name="code" class="html">android:id="@android:id/tabs"
MainActivity.java :
public class MainActivity extends TabActivity{ private TabHost tabhost; public static Target target; public void onCreate(Bundle saveInstanceState){ super.onCreate(saveInstanceState); setContentView(R.layout.activity_main); tabhost = getTabHost(); tabhost.addTab(tabhost.newTabSpec("tab_1").setIndicator("提醒", getResources(). getDrawable(R.drawable.ic_launcher)).setContent(new Intent(this, RemindActivity.class))); tabhost.addTab(tabhost.newTabSpec("tab_2").setIndicator("设置", getResources(). getDrawable(R.drawable.setting_tab_icon)).setContent(new Intent(this, SettingActivity.class))); tabhost.addTab(tabhost.newTabSpec("tab_3").setIndicator("关于", getResources(). getDrawable(R.drawable.about_tab_icon)).setContent(new Intent(this, AboutActivity.class))); // 设置默认在第一个tab tabhost.setCurrentTab(0); /*tabhost.setOnTabChangedListener(new OnTabChangeListener(){ @Override public void onTabChanged(String tabId) { // TODO Auto-generated method stub if(tabId.equals("tab_1")){ Toast.makeText(MainActivity.this, "in tab 1", Toast.LENGTH_SHORT).show(); } else if(tabId.equals("tab_2")){ Toast.makeText(MainActivity.this, "in tab 2", Toast.LENGTH_SHORT).show(); } else if(tabId.equals("tab_3")){ Toast.makeText(MainActivity.this, "in tab 3", Toast.LENGTH_SHORT).show(); } } });*/ } }
http://www.apkbus.com/forum.php?mod=viewthread&tid=140042