我知道如何为imageview做一个选择器以及如何为textView做一个选择器,现在我有一个tabwidget,其中包含选项卡,每个选项卡下面都有图像和文本视图,我的问题是如何更改图像视图的背景和颜色当用户单击选项卡时,将显示文本视图。
You have to use TabHost.TabSpec.setIndicator(View view) to define your own layout where you set your selectors. You can reuse tab_indicator.xml
layout, can be found in platforms/android-xx/data/res/drawable
.
excerpt:
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.