我在我的一项活动中使用标签视图。我想根据选项卡的选择更改选项卡的可绘制性。就像这样——我有 4 张图像 T11、T12、T21、T22。我想最初选择选项卡 1 来设置图像 T11 和 T22。现在我想在选择 Tab 2 后立即将图像更改为 T12 和 T21。
到目前为止,我尝试通过可绘制类型的 xml 文件使用:
左标签(tab1)的可绘制 -
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
style="?attr/left_active" />
<item android:state_window_focused="false" android:state_enabled="false"
style="?attr/left_inactive" />
<item android:state_pressed="true" android:state_enabled="true"
style="?attr/left_active" />
<item android:state_pressed="true" android:state_enabled="false"
style="?attr/left_inactive" />
</selector>
右标签(Tab2)可绘制--
<item android:state_window_focused="false" android:state_enabled="true"
style="?attr/right_active" />
<item android:state_window_focused="false" android:state_enabled="false"
style="?attr/right_inactive" />
<item android:state_pressed="true" android:state_enabled="true"
style="?attr/right_active" />
<item android:state_pressed="true" android:state_enabled="false"
style="?attr/right_inactive" />
活动中:
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1", getResources().getDrawable(R.drawable.left)).setContent(new Intent(this, Left.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("Tab2", getResources().getDrawable(R.drawable.right))
.setContent(new Intent(this, Right.class)));
tabHost.setCurrentTab(1);
请帮忙...