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