private void buildTabSpec() { List<TabItem> tabItems = getTabItems(); for (TabItem tabItem : tabItems) { View tabItemView = getLayoutInflater().inflate(R.layout.item_tab_nav_main, null); TextView tvTabItem = (TextView) tabItemView.findViewById(R.id.tab_item_tv); LinearLayout tab_layout = (LinearLayout) tabItemView.findViewById(R.id.tab_layout); tvTabItem.setText(tabItem.getTitle()); tvTabItem.setCompoundDrawablesWithIntrinsicBounds(0, tabItem.getIcon(), 0, 0); tab_layout.setBackgroundResource(R.drawable.bg_tab_footer); TabSpec tabSpec = getTabHost().newTabSpec(tabItem.getTitle()); tabSpec.setIndicator(tabItemView); tabSpec.setContent(tabItem.getIntent()); getTabHost().addTab(tabSpec); } }
/** * Add a TabItem to the index; * * @param index * @param tabItem */ public synchronized void addTab(int index, TabItem tabItem) { if (index < 0 || index > getTabItemCount()) throw new IllegalArgumentException(); if (index >= TabModel.MAX_TABS_AMOUNT) return; GroupingContainerModel groupingContainerModel = tabItem.getGroupingContainerModel(); getWidgetModel().addChild(index, groupingContainerModel); getTabFigure().addTab((String) tabItem.getPropertyValue(TabProperty.TITLE), index); tabItemList.add(index, tabItem); initTabLabel(index, tabItem); rightShiftTabProperties(index); // apply tab properties from TabItem to TabModel for (TabProperty tabProperty : TabProperty.values()) { String propID = TabModel.makeTabPropID(tabProperty.propIDPre, index); getWidgetModel().setPropertyValue(propID, tabItem.getPropertyValue(tabProperty)); } // update property sheet getWidgetModel() .setPropertyValue(TabModel.PROP_TAB_COUNT, getWidgetModel().getChildren().size(), false); for (TabProperty tabProperty : TabProperty.values()) { String propID = TabModel.makeTabPropID(tabProperty.propIDPre, getWidgetModel().getChildren().size() - 1); getWidgetModel().setPropertyVisible(propID, true); } // update active tab index to the new added tab updateTabAreaSize(); setActiveTabIndex(index); }
private void initTabLabel(int index, TabItem tabItem) { for (TabProperty tabProperty : TabProperty.values()) { Object propValue = tabItem.getPropertyValue(tabProperty); setTabFigureProperty(index, tabProperty, propValue); } }