<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:id="@+id/realtabcontent" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1"/> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="4dip"> <net.oschina.app.widget.MyFragmentTabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dip" /> <View android:layout_width="match_parent" android:layout_height="1px" android:background="#D6D6D6" /> </RelativeLayout> <!-- 快速操作按钮--> <ImageView android:id="@+id/quick_option_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:contentDescription="@null" android:src="@drawable/btn_quickoption_selector" /> </FrameLayout> </LinearLayout>@Override public void initView() { mDoubleClickExit = new DoubleClickExitHelper(this); mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); if (android.os.Build.VERSION.SDK_INT > 10) { mTabHost.getTabWidget().setShowDividers(0); } initTabs(); // 中间按键图片触发 mAddBt.setOnClickListener(this); mAddBt.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { startActivity(new Intent(MainActivity.this, NetSetupActivity.class)); return true; } }); mTabHost.setCurrentTab(0); mTabHost.setOnTabChangedListener(this); }private void initTabs() { MainTab[] tabs = MainTab.values(); final int size = tabs.length; for (int i = 0; i < size; i++) { MainTab mainTab = tabs[i]; // Tab的tag TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName())); // Tab的自定义布局view View indicator = LayoutInflater.from(getApplicationContext()).inflate(R.layout.tab_indicator, null); TextView title = (TextView) indicator.findViewById(R.id.tab_title); Drawable drawable = this.getResources().getDrawable(mainTab.getResIcon()); title.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); if (i == 2) { indicator.setVisibility(View.INVISIBLE); mTabHost.setNoTabChangedTag(getString(mainTab.getResName())); } title.setText(getString(mainTab.getResName())); tab.setIndicator(indicator); tab.setContent(new TabContentFactory() { @Override public View createTabContent(String tag) { return new View(MainActivity.this); } }); mTabHost.addTab(tab, mainTab.getClz(), null); mTabHost.getTabWidget().getChildAt(i).setOnTouchListener(this); } }@Override public void onTabChanged(String tabId) { final int size = mTabHost.getTabWidget().getTabCount(); for (int i = 0; i < size; i++) { View v = mTabHost.getTabWidget().getChildAt(i); if (i == mTabHost.getCurrentTab()) { v.setSelected(true); } else { v.setSelected(false); } } }@Override public boolean onTouch(View v, MotionEvent event) { super.onTouchEvent(event); boolean consumed = false; // use getTabHost().getCurrentTabView to decide if the current tab is touched again if (event.getAction() == MotionEvent.ACTION_DOWN && v.equals(mTabHost.getCurrentTabView())) { // use getTabHost().getCurrentView() to get a handle to the view which is displayed in the tab - and to get this views context Fragment currentFragment = getCurrentFragment(); if (currentFragment != null && currentFragment instanceof OnTabReselectListener) { OnTabReselectListener listener = (OnTabReselectListener) currentFragment; // 回调当前页的刷新方法 listener.onTabReselect(); consumed = true; } } return consumed; }private Fragment getCurrentFragment() { return getSupportFragmentManager().findFragmentByTag(mTabHost.getCurrentTabTag()); }public enum MainTab { NEWS(0, R.string.main_tab_name_news, R.drawable.tab_icon_new, NewsViewPagerFragment.class), TWEET(1, R.string.main_tab_name_tweet, R.drawable.tab_icon_tweet, TweetsViewPagerFragment.class), QUICK(2, R.string.main_tab_name_quick, R.drawable.tab_icon_new, null), EXPLORE(3, R.string.main_tab_name_explore, R.drawable.tab_icon_explore, ExploreFragment.class), ME(4, R.string.main_tab_name_my, R.drawable.tab_icon_me, MyInformationFragment.class); private int idx; private int resName; private int resIcon; private Class<?> clz; private MainTab(int idx, int resName, int resIcon, Class<?> clz) { this.idx = idx; this.resName = resName; this.resIcon = resIcon; this.clz = clz; }}