imageview のセレクターを作成する方法と textView のセレクターを作成する方法を知っています。タブを含むタブウィジェットがあり、各タブの下に画像とテキストビューがあります。私の質問は、画像ビューの背景と色を変更する方法ですo ユーザーがタブをクリックしたときのテキスト ビュー。
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 に答える