Home » Android » view – Android – Make default tabs but without any content

view – Android – Make default tabs but without any content

Posted by: admin June 15, 2020 Leave a comment

Questions:

So I want to have tabs with default style but I want to handle content by myself.
If I try to create them only with:

TabSpec tabT = mainTabHost.newTabSpec("tabT").setIndicator("T");
tabHost.add(tabT);

I get error that content is not specified.

Then I tried to add tabs with tabwidget directly but I don’t know how to get default style of tabs.

Any advice?

How to&Answers:

Try TabContentFactory with an empty View:

tabSpec.setContent(new EmptyTabFactory());

the factory class:

private class EmptyTabFactory implements TabContentFactory {

    @Override
    public View createTabContent(String tag) {
        return new View(mContext);
    }

}

Answer:

To set content you should use the method setContent:

TabSpec tabT = mainTabHost.newTabSpec("tabT").setIndicator("T").setContent(viewId);

Take a look here for getting an example.