Reputation: 1073
I am using example from Action Bar Sherlock Fragment Tabs Pager. What I am trying to do is set different icon image for each tab. Text for each tab is not necessary, it can be included in image file. Is there a simple solution to this problem.
Upvotes: 3
Views: 3444
Reputation: 215
This is what I do and works. Create the tabs menu and add the text (no needed in your case), the fragment to open and the Icon:
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(true);
Tab tab = actionBar.newTab()
.setText("Tab title")
.setTabListener(new ResultadosSorteosFragment())
.setIcon(R.drawable.resultados_sorteos);
My problem is that I want to put the image under the text. I hope it´s what you need
Upvotes: 5
Reputation: 934
If you follow the sample in the ABS FragmentTabsPager, this is what you can do:
This is to just show icon + label text :
mTabsAdapter.addTab(mTabHost.newTabSpec("category").setIndicator("my label text", getResources().getDrawable(R.drawable.collections_labels) ),
CategoryFragmentActivity.CategoryFragment.class, null); //
This is to just show icon only:
mTabsAdapter.addTab(mTabHost.newTabSpec("category").setIndicator("", getResources().getDrawable(R.drawable.collections_labels) ),
CategoryFragmentActivity.CategoryFragment.class, null); //
Upvotes: 3