Question

How to use tabs in android after depreciation of tab activity? by using sherlock and fragments i am able to do tabing but i want to set tab image as whole not tab icon... i don't need black bg with my image i want my image on whole tab. here is my code

private FragmentTabHost mTabHost;
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
           // mTabHost.setup(this, getSupportFragmentManager(), R.id.tabFrameLayout);
            mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);

            mTabHost.addTab(
                    mTabHost.newTabSpec("tab1").setIndicator("",
                            getResources().getDrawable(R.drawable.tab8)),
                    FragmentTab.class, null);
            mTabHost.addTab(
                    mTabHost.newTabSpec("tab2").setIndicator("Tab 2",
                            getResources().getDrawable(R.drawable.tab9)),
                    FragmentTab.class, null);
            mTabHost.addTab(
                    mTabHost.newTabSpec("tab3").setIndicator("Tab 3",
                            getResources().getDrawable(android.R.drawable.star_on)),
                    FragmentTab.class, null);
            mTabHost.addTab(
                    mTabHost.newTabSpec("tab4").setIndicator("Tab 4",
                            getResources().getDrawable(android.R.drawable.star_on)),
                    FragmentTab.class, null);

Help Required :)
Was it helpful?

Solution

I did it by using tabhost, you can use tabhost without tabactivity following is the code.

final TabHost tabHost=(TabHost)findViewById(R.id.tabhost);
    tabHost.setup();

        final TabSpec spec1 = tabHost.newTabSpec("Tab1");
        View view = LayoutInflater.from(this).inflate(R.layout.tabbar8, tabHost.getTabWidget(), false);
        spec1.setIndicator(view);
        spec1.setContent(R.id.tab1);

where tabbar8 is layout which i want to set on my first tab

OTHER TIPS

You can completely customize the ActionBar tabs by using setCustomView() on the ActionBar.Tab. You'll define an XML layout for the tab, then set similar to:

// Home tab
ActionBar.Tab tabHome = mActionBar.newTab();
tabHome.setText("Home");        
LinearLayout layoutLinear = (LinearLayout)inflater.inflate(R.layout.layout_tab_standard, null);
TextView title = (TextView)layoutLinear.findViewById(R.id.title);
title.setText(strTabTitle);
tabHome.setCustomView(layoutLinear);
mActionBar.addTab(tabHome);

so you can put your ImageView, or set a background drawable, on the linear layout you define (R.layout.layout_tab_standard in this example).

You should also review the Action Bar Style Generator (http://jgilfelt.github.io/android-actionbarstylegenerator/), you might find this useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top