我在我的应用程序中使用tabhost。我们可以为每个标签提供单独的宽度属性吗?即一个宽度较大而另一个较小?请给我示例。如果可能,请给我代码。
编辑:
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);
}
}
答案 0 :(得分:2)
您可以通过以下代码实现此目的 - :
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 50;