<android.support.v4.app.FragmentTabHost    xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/tabhost"    android:layout_width="match_parent"    android:layout_height="match_parent"><TabWidget    android:id="@+id/tabwidget_tabs"    android:layout_width="match_parent"        android:layout_height="wrap_content"/><FrameLayout         android:id="@+id/layout_container_tabcontent"         android:layout_width="match_parent"         android:layout_height="match_parent"/></android.support.v4.app.FragmentTabHost>

import android.os.Bundle;import android.support.v4.app.FragmentActivity;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentTabHost;import android.view.Menu;import android.widget.TabHost.TabSpec;public class MainActivity extends FragmentActivity {private FragmentTabHost tabHost;private Bundle bundle1, bundle2, bundle3, bundle4;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tabHost = (FragmentTabHost) findViewById(R.id.tabhost);FragmentManager manager = getSupportFragmentManager();tabHost.setup(this, manager, R.id.layout_container_tabcontent);TabSpec tabSpec1 = tabHost.newTabSpec("records");tabSpec1.setIndicator("记录");bundle1 = new Bundle();bundle1.putInt("tabIndex", 1);TabSpec tabSpec2 = tabHost.newTabSpec("contacts");tabSpec2.setIndicator("联系人");bundle2 = new Bundle();bundle2.putInt("tabIndex", 2);TabSpec tabSpec3 = tabHost.newTabSpec("collections");tabSpec3.setIndicator("收藏夹");bundle3 = new Bundle();bundle3.putInt("tabIndex", 3);TabSpec tabSpec4 = tabHost.newTabSpec("groups");tabSpec4.setIndicator("群组");bundle4 = new Bundle();bundle4.putInt("tabIndex", 4);tabHost.addTab(tabSpec1, DummyFragment.class, bundle1);tabHost.addTab(tabSpec2, DummyFragment.class, bundle2);tabHost.addTab(tabSpec3, DummyFragment.class, bundle3);tabHost.addTab(tabSpec4, DummyFragment.class, bundle4);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.main, menu);return true;}}

import android.os.Bundle;import android.support.v4.app.Fragment;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;public class DummyFragment extends Fragment {private TextView text_dummyfragment;private Bundle bundle = null;private int tabIndex = 0;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);bundle = getArguments();tabIndex = bundle.getInt("tabIndex");}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {View view = inflater.inflate(R.layout.fragment_dummy, container, false);text_dummyfragment = (TextView) view.findViewById(R.id.text_dummyfragment);Log.i("", "==" + tabIndex);switch (tabIndex) {case 1:text_dummyfragment.setText("这个是记录页面");break;case 2:text_dummyfragment.setText("这个是联系人页面");break;case 3:text_dummyfragment.setText("这个是收藏夹页面");break;case 4:text_dummyfragment.setText("这个是群组页面");break;default:break;}return view;}}

更多相关文章

  1. android 设置主页面的方式
  2. Android完整的Activity页面
  3. Android联系人数据库全
  4. android获取手机中的短信和,android获取手机通讯录联系人和号码
  5. 解决activity加上Theme.Translucent.NoTitleBar 页面跳转显示桌
  6. Activity页面切换的效果
  7. Android联系人数据库全解析(1)
  8. Android 防止启动页面(SplashActivity)被多次启动(笔记)
  9. Android联系人3--联系人分组相关

随机推荐

  1. Java,Android Integer和byte的相互转换,Jav
  2. 用ndk-build 工具手动生成编译android原
  3. Android 自定义View(API解析+Demo)
  4. 图片中的毕加索【Picasso】
  5. Android 新手常见的10个误区(下)
  6. android 动态控制状态栏显示和隐藏的方法
  7. android视图继承关系
  8. Android通过PagerSnapHelper改造Recycler
  9. Android文件系统的结构及目录用途、操作
  10. 查询存储空间的代码