Reputation: 635
I am using tabhost in my application. Can we give separate width property for each tab? i.e, one with larger width and other with smaller?please give me sample example.if possible means give me code.
EDIT:
public class TabBarSimple extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
TabSpec dbspec = tabHost.newTabSpec("DashBoard");
dbspec.setIndicator("Dashboard", getResources().getDrawable(R.drawable.dashboard));
Intent dbIntent = new Intent(this, PhotosActivity.class);
dbspec.setContent(dbIntent);
tabHost.addTab(dbspec);
TabSpec orderspec = tabHost.newTabSpec("Orders");
orderspec.setIndicator("Orders", getResources().getDrawable(R.drawable.orders));
Intent orderIntent = new Intent(this, SongsActivity.class);
orderspec.setContent(orderIntent);
tabHost.addTab(orderspec);
TabSpec settingspec = tabHost.newTabSpec("Customers");
settingspec.setIndicator("Customers", getResources().getDrawable(R.drawable.customers));
Intent settingIntent = new Intent(this, VideosActivity.class);
settingspec.setContent(settingIntent);
tabHost.addTab(settingspec);
TabSpec aboutspec = tabHost.newTabSpec("Settings");
aboutspec.setIndicator("Settings", getResources().getDrawable(R.drawable.settings));
Intent aboutIntent = new Intent(this, PhotosActivity.class);
aboutspec.setContent(aboutIntent);
tabHost.addTab(aboutspec);
TabSpec logoutspec = tabHost.newTabSpec("Logout");
logoutspec.setIndicator("Logout", getResources().getDrawable(R.drawable.logout));
Intent logoutIntent = new Intent(this, SongsActivity.class);
logoutspec.setContent(logoutIntent);
tabHost.addTab(logoutspec);
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
//tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117"));
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 100;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 50;
}
tabHost.getTabWidget().setCurrentTab(0);
//tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#C35817"));
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_indicator);
}
public void onTabChanged(String tabId) {
TabHost tabHost = getTabHost();
// TODO Auto-generated method stub
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
//tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117"));
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator);
}
//tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#C35817"));
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.tab_indicator);
}
}
Upvotes: 0
Views: 3213
Reputation: 6691
You can achieve this by the code below -:
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 50;
Upvotes: 2