private static View prepareTabView(Context context, int textId, int drawable) { View view = LayoutInflater.from(context).inflate(R.layout.tab_layout, null); // setting text and image // ... // Write your own code here return view; } public static void addTab(TabHost host, int title, String tag, int drawable, int layout) { TabHost.TabSpec spec = host.newTabSpec(tag); spec.setContent(layout); View view = prepareTabView(host.getContext(), title, drawable); spec.setIndicator(view); host.addTab(spec); }
private TabSpec setupTab(final View view, final TabHost mTabHost, final int imageId, final String tag) { final View tabview = createTabView(mTabHost.getContext(), imageId, tag); TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() { public View createTabContent(String tag) {return view;} }); return setContent; } private static View createTabView(final Context context, final int imageId, final String text) { View view = LayoutInflater.from(context).inflate(R.layout.tab_with_icon, null); TextView tv = (TextView) view.findViewById(R.id.tabTitle); tv.setText(text); ImageView iv = (ImageView) view.findViewById(R.id.iconImage); if (iv != null) iv.setImageResource(imageId); view.setTag(text); view.setBackgroundResource(R.drawable.tab_bg_selector); // only refresh on watchlist if (text.equals(context.getString(R.string.WatchList))) refreshTab(context, view); else { RelativeLayout countLayout = (RelativeLayout) view.findViewById(R.id.countLayout); if (countLayout != null) countLayout.setVisibility(View.GONE); } return view; }
final TabHost th = (TabHost) findViewById(android.R.id.tabhost); final View tabview = createTabView(th.getContext(), tag); final TabSpec setContent = th.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() { public View createTabContent(String tag) {
private static View prepareTabView(Context context, String text, int drawable) { View view = LayoutInflater.from(context).inflate(R.layout.tab_layout, null); ((TextView) view.findViewById(R.id.tabTitle)).setText(text); ((ImageView) view.findViewById(R.id.tabImage)).setImageResource(drawable); return view; } public static void addTab(TabsAdapter adapter, TabHost host, String title, String tag, int drawable, Class cl) { TabHost.TabSpec spec = host.newTabSpec(tag); View view = prepareTabView(host.getContext(), title, drawable); spec.setIndicator(view); adapter.addTab(spec, cl,null); }
/** * * @param view * @param tag * @param i */ private void setupTab(View view, String tag, Intent i, Intent original) { /* * Pass on all original. */ if(original.getExtras() != null) { i.putExtras(original); } View tabview = createTabView(mTabHost.getContext(), tag); TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(i); mTabHost.addTab(setContent); }
final View tabview = createTabView(th.getContext(), tag);
View tabview = createTabView(tabHost.getContext(), tag); if(tag.equals("Inicio")){
spec2.setIndicator(createTabView(tabHost.getContext(), "Contacts", R.drawable.tab_account)); spec2.setContent(new Intent(TabsActivity.this, ContactsActivity.class)); spec3.setIndicator(createTabView(tabHost.getContext(), "Chats", R.drawable.tab_settings)); spec3.setContent(new Intent(TabsActivity.this, ChatsActivity.class)); spec4.setIndicator(createTabView(tabHost.getContext(), "More", R.drawable.tab_more)); spec4.setContent(new Intent(TabsActivity.this, ChatsActivity.class));
View tabview = createTabView(mTabHost.getContext(), tag); TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(res); mTabHost.addTab(setContent);
View tabview = createTabView(mTabHost.getContext(), tag);
View tabview = createTabView(mTabHost.getContext(), tag);
View tabview = createTabView(tabHost.getContext(), tag); TabSpec setContent = tabHost.newTabSpec(tag); setContent.setIndicator(tabview);
private TabHost mTabHost ; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.my_layout); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); // We create a webview for one tab for example WebView wv = new WebView(this); // add url and options on this webview setupTab(wv, "My Title"); } private void setupTab(final View view, final String tag) { View tabview = createTabView(mTabHost.getContext(), tag); TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() { public View createTabContent(String tag) {return view;} }); mTabHost.addTab(setContent); } // this is the method for customize tabs private static View createTabView(final Context context, final String text) { View view = LayoutInflater.from(context).inflate(R.layout.layout_tabwidget_custom, null); TextView tv = (TextView) view.findViewById(R.id.tabsText); tv.setText(text); return view; }
View tabview = createTabView(tabHost.getContext(), tag);
View view = prepareTabView(tabHost.getContext(), title, drawable); tabSpec.setIndicator(view);
View tabview = createTabView(mTabHost.getContext(), tag);
View indicator=LayoutInflater.from(mTabHost.getContext()).inflate(R.layout.tabs_bg_view, null); TextView tv=(TextView)indicator.findViewById(R.id.tabsText);
tabSpec.setIndicator(getTabIndicator(tabHost.getContext(), tabValue, icon)); tabSpec.setContent(new Dummy(getActivity())); return tabSpec;