如何将适合的图像设置为tabhost中的单个选项卡

时间:2017-01-03 14:34:03

标签: android android-layout

我想设置必须适合标签的图像 在我的tabhost中有2个标签 这是我的代码

tab =(TabHost) findViewById(R.id.tabhost);
tab.setup();
TabHost.TabSpec spec = tab.newTabSpec("tag1");
spec.setIndicator("",getResources().getDrawable(R.drawable.loginpic));
spec.setContent(R.id.tab1);
tab.addTab(spec);

spec = tab.newTabSpec("tag2");
spec.setIndicator("",getResources().getDrawable(R.drawable.signuppic));
spec.setContent(R.id.tab2);
tab.addTab(spec);

图片很小,没有填满整个标签

我该怎么做?

1 个答案:

答案 0 :(得分:0)

试试这个,

Drawable loginpic= getResources().getDrawable(R.drawable.loginpic);
StateListDrawable selector = new StateListDrawable();
selector.addState(new int[0], selectedIcon);
spec.setIndicator("Tab 1", selector);