要得到这样的界面:一个大的框架下有三个tab,tab之间可以切换


一、TabWidget

这是我的实现

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>

注意tabhost 和 tabs 都是系统的id,不可以重新命名
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)));// 设置默认在第一个tabtabhost.setCurrentTab(0);/*tabhost.setOnTabChangedListener(new OnTabChangeListener(){@Overridepublic void onTabChanged(String tabId) {// TODO Auto-generated method stubif(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();}}});*/}}

要实现选中某个tab,tab的图片会变化,要加入个selector.xml

http://www.apkbus.com/forum.php?mod=viewthread&tid=140042


二、ActivityGroup+Button

网上也有人是这样实现的,类似上面

三、ViewPager

高大上,现在的微信就是ViewPager http://blog.csdn.net/wangjinyu501/article/details/8144332

更多相关文章

  1. TextView 加链接所有方法
  2. Android(安卓)布局 & 一些控件
  3. android EditText 全面阐述
  4. 实现底部导航栏中间凸起
  5. Android(安卓)TextView 文字居中 .
  6. Android(安卓)Fresco属性大全,中文说明
  7. EditView某些属性说明
  8. Android中TextVIew一些属性
  9. Android(安卓)TextView 文字居中

随机推荐

  1. Android Studio Termanal打不开,提示java.
  2. 【Android】神奇的android:clipChildren
  3. Android Activity api 详解 - runOnUiThr
  4. android 对话框(Dialog)使用(2)
  5. 【Android】this和this.getApplictionCon
  6. Android View如何获取焦点
  7. 关于Android视频播放的一些事
  8. Android Bitmap 内存以及OOM问题讨论
  9. 关于AndroidManifest.xml中的android:deb
  10. Android判断当前网络是否可用