I checked one of the solution which asks to use .setIndicator(View view) and add your Tab title and icon in your layout file. But I want to add dynamically FragmentTabHost along with setting its icons. So can anyone answer how to use .setIndicator(View view)
with an example of adding say 3 tabs dynamically?
public class MainActivity extends ActionBarActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
Drawable icon = getResources().getDrawable(R.drawable.icon);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab 1", icon), FragmentTab.class, null);
}
}