midnight
midnight

Reputation: 3412

TabHost: make all tabs unselected

Is there a way to unselect all the elements in the TabHost. I guess I can make a stub tab, which will have a width of 0dp. Is it a way to go ? How is it done -how do I apply style to one particular tab ?

Upvotes: 0

Views: 1801

Answers (2)

Dumitru Hristov
Dumitru Hristov

Reputation: 1499

To make the tab stretch away:

fakeTab.setVisibility(View.GONE);

Upvotes: 2

Slickelito
Slickelito

Reputation: 1786

If that's the approach your going with Id suggest you create your own Tab View for the "fake tab".

Something like this

private class TabView extends FrameLayout  {
    public TabView(Context c) {
        super(c);

        View indicator = new View(c);
        //Might even wanna go for 0 here?
        LayoutParams params = new FrameLayout.LayoutParams(1, 1);
        indicator.setLayoutParams(params);

        addView(indicator);
    }
}

Then just add it to your TabHost in the following way :

    TabView fakeTab = new TabView(this, 0, "faketab");
    spec = tabHost.newTabSpec("about").setIndicator(fakeTab);
    tabHost.addTab(spec);

When you want to display all tabs as unselected you simple make the TabHost select your fake tab.

Upvotes: 1

Related Questions