4
我试图更改状态更改时的选项卡图标。所有工作正常,如果我用绘制从下面的XML:android更改选项卡图标
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/d_selected"
android:state_selected="true" />
<item android:drawable="@drawable/d_normal" />
</selector>
不过,现在我需要加载从数据/数据文件夹的图像和绘图“d”和“DSEL”从这些图像中产生。使用下面的代码只显示“dSel”,其他标签图像不会出现!谢谢
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
selector.addState(new int[]{ android.R.attr.state_pressed }, d);
selector.addState(new int[]{ android.R.attr.state_selected }, dSel);
selector.addState(new int[]{ android.R.attr.state_focused }, d);
icon.setImageDrawable(selector);
//icon.setImageResource(drawableId); used with other method described, if related to xml
尝试这种'ImageView的图标=(ImageView的)getTabWidget()getChildAt(0).findViewById(android.R.id.icon)。 icon .setImageDrawable(getResources()。getDrawable(R.drawable.state_pressed));' – 2012-03-31 22:05:42
mmm,你在哪里将图像分配给state_press? – Jaume 2012-04-01 09:09:34