These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TabHost class.
// Unfortunately when TabHost changes the current tab, it kindly // also takes care of putting focus on it when not in touch mode. // The jerk. // This hack tries to prevent this from pulling focus out of our // ViewPager. TabWidget widget = mTabHost.getTabWidget(); int oldFocusability = widget.getDescendantFocusability(); widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); mTabHost.setCurrentTab(position); widget.setDescendantFocusability(oldFocusability); } @Override public void onPageScrollStateChanged(int state) { } } }
@Override public void onPageSelected(final int position) { super.onPageSelected(position); host.setCurrentTab(position); } @Override public void onTabChanged(String tabId) { updateCurrentItem(host.getCurrentTab()); } @Override public View createTabContent(String tag) { return ViewUtils.setGone(new View(getApplication()), true); } /** * Create pager adapter
/** * Initialise the Tab Host */ private void initialiseTabHost(Bundle args) { mTabHost = (TabHost)findViewById(android.R.id.tabhost); mTabHost.setup(); TabInfo tabInfo = null; TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Tab 1"), ( tabInfo = new TabInfo("Tab1", Tab1Fragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Tab 2"), ( tabInfo = new TabInfo("Tab2", Tab2Fragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("Tab 3"), ( tabInfo = new TabInfo("Tab3", Tab3Fragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); // Default to first tab this.onTabChanged("Tab1"); // mTabHost.setOnTabChangedListener(this); } /**
setExtras(extras, backlog, "backlog"); setExtras(extras, current, "current"); setExtras(extras, icebox, "icebox"); } tabHost.clearAllTabs(); tabHost.addTab(tabHost.newTabSpec("tab_done") .setIndicator("Done") .setContent(done)); tabHost.addTab(tabHost.newTabSpec("tab_current") .setIndicator("Current") .setContent(current)); tabHost.addTab(tabHost.newTabSpec("tab_backlog") .setIndicator("Backlog") .setContent(backlog)); tabHost.addTab(tabHost.newTabSpec("tab_icebox") .setIndicator("Icebox") .setContent(icebox)); tabHost.setCurrentTab(1);
/** * Initialise the Tab Host */ private void initialiseTabHost(Bundle args) { mTabHost = (TabHost)findViewById(android.R.id.tabhost); mTabHost.setup(); TabInfo tabInfo = null; TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Tab 1"), ( tabInfo = new TabInfo("Tab1", Tab1Fragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Tab 2"), ( tabInfo = new TabInfo("Tab2", Tab2Fragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("Tab 3"), ( tabInfo = new TabInfo("Tab3", Tab3Fragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); // Default to first tab //this.onTabChanged("Tab1"); // mTabHost.setOnTabChangedListener(this); } /**
private void setupTabs() { Intent projects = new Intent(this, Projects.class); Intent activities = new Intent(this, Activities.class); tabHost.clearAllTabs(); tabHost.addTab(tabHost.newTabSpec("tab_projects") .setIndicator("My Projects") .setContent(projects)); tabHost.addTab(tabHost.newTabSpec("tab_activities") .setIndicator("Activity Feed") .setContent(activities)); } }
@RealObject TabActivity realTabActivity; TabHost tabhost; @Implementation public TabHost getTabHost() { if (tabhost==null) { tabhost = new TabHost(realTabActivity); } return tabhost; } @Implementation public TabWidget getTabWidget() { return getTabHost().getTabWidget(); } }
*/ @Override public Widget create(Activity activity, int handle) { // Construct the tab host that fills the whole screen. TabHost tabHost = new TabHost( activity, null ); tabHost.setLayoutParams( new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT ) ); // Create the visual structure of the tab host LinearLayout tabRootView = createTabRoot( activity ); tabHost.addView( tabRootView ); // Must be called when using views instead of activities to fill // a tabs content tabHost.setup( ); tabHost.setOnTabChangedListener( new TabChangeListener( handle ) );
@Implementation public void addTab(android.widget.TabHost.TabSpec tabSpec) { tabSpecs.add(tabSpec); View indicatorAsView = shadowOf(tabSpec).getIndicatorAsView(); if (indicatorAsView != null) { realObject.addView(indicatorAsView); } } @Implementation public void setCurrentTab(int index) { currentTab = index; if (listener != null) { listener.onTabChanged(getCurrentTabTag()); } } @Implementation public void setCurrentTabByTag(String tag) { for (int x = 0; x < tabSpecs.size(); x++) {
final boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent .getType()); // Dismiss menu provided by any children activities Activity activity = getLocalActivityManager().getActivity( mTabHost.getCurrentTabTag()); if (activity != null) { activity.closeOptionsMenu(); } // Tell the children activities that they should ignore any possible // saved // state and instead reload their state from the parent's intent intent.putExtra(EXTRA_IGNORE_STATE, true); // Remember the old manually selected tab index so that it can be // restored if it is // overwritten by one of the programmatic tab selections final int savedTabIndex = mLastManuallySelectedTab;
13: setContentView(R.layout.main);
14:
15: TabHost tabHost = getTabHost();
16:
17: // Tab for Photos
17: setContentView(R.layout.main);
18:
19: TabHost tabHost = getTabHost();
20:
21: // Inbox Tab