我正在尝试在 android 中使用四个选项卡选项卡做一个简单的选项卡应用程序。我的问题是,当我想显示图标和指示器时,它只显示文本指示器,我想在 tabhost 上显示可绘制和指示器文本,这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
//hide title bar
BasicDisplaySettings.toggleTaskBar(SimasCardMainActivity.this, false);
//show status bar
BasicDisplaySettings.toggleStatusBar(SimasCardMainActivity.this, true);
super.onCreate(savedInstanceState);
setContentView(R.layout.simascard);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, TerbaruSimasCard.class);
spec = tabHost.newTabSpec("Terbaru").setIndicator("Terbaru",
res.getDrawable(R.drawable.menu_terbaru))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MerchantSimasCard.class);
spec = tabHost.newTabSpec("Merchant").setIndicator("Merchant",
res.getDrawable(R.drawable.menu_merchant))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, TentangSimasCard.class);
spec = tabHost.newTabSpec("Tentang").setIndicator("Tentang",
res.getDrawable(R.drawable.menu_tentang))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, FaqSimasCard.class);
spec = tabHost.newTabSpec("FAQ").setIndicator("FAQ",
res.getDrawable(R.drawable.menu_faq))
.setContent(intent);
tabHost.addTab(spec);
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){
tabHost.getTabWidget().getChildAt(i).setPadding(0,0,0,0);
tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null);
}
tabHost.setCurrentTab(0);
}
// @Override
public void onBackPressed() {
finish();
}
当我使用
spec = tabHost.newTabSpec("Tentang").setIndicator("",
res.getDrawable(R.drawable.menu_tentang))
.setContent(intent);
它会显示一个图标,但是当我在上面添加文本时,setIndicator
例如setIndicator("Tentang")
它在 tabhost 上仅显示指示符文本,我不知道我的代码哪里出了问题,我试图增加标签高度,但它没有t工作,我希望有人可以帮助我解决我的问题。谢谢你