0

我知道如何为 imageview 制作选择器以及如何为 textView 制作选择器,现在我有一个包含选项卡的 tabwidget,每个选项卡下面都有图像和文本视图,我的问题是如何更改图像视图的背景和颜色o 用户单击选项卡时的文本视图。

4

1 回答 1

0

您必须使用TabHost.TabSpec.setIndicator(View view)来定义您自己的布局,您可以在其中设置选择器。您可以重用tab_indicator.xml布局,可以在platforms/android-xx/data/res/drawable.

摘抄:

mTabHost = (TabHost) findViewById(android.R.id.tabhost);

private View createTabView(CharSequence label, Drawable icon) {
    View tabIndicator = LayoutInflater.from(mContext).inflate(R.layout.tab_indicator, mTabHost.getTabWidget(), false);
    TextView tv = (TextView) tabIndicator.findViewById(R.id.title);
    tv.setText(label);
    ImageView iv = (ImageView) tabIndicator.findViewById(R.id.icon).
    iv.setDrawable(icon);
    return tabIndicator;
}

public void addTab(CharSequence label, Drawable icon) {
    View tabIndicator = createTabView(label, icon);
    TabHost.TabSpec tabSpec = mTabHost.newTabSpec(label.toString()).setIndicator(tabIndicator).setContent(...);
    mTabHost.addTab(tabSpec);
}
于 2012-07-14T16:09:28.140 回答