我正在創建一個動態Imageview。設置Imageview背景
ImageView btnSend = new ImageView (this);
我需要把包含圖像的狀態的佈局,這是XML:
<? xml version = "1.0" encoding = "utf-8"?>
<selector
xmlns: android = "http://schemas.android.com/apk/res/android">
<item
android: state_focused = "true"
android: state_pressed = "false"
android: drawable = "@ drawable/button_state3" />
<item
android: state_focused = "true"
android: state_pressed = "true"
android: drawable = "@ drawable/button_state2" />
<item
android: state_focused = "false"
android: state_pressed = "true"
android: drawable = "@ drawable/button_state2" />
<item
android: drawable = "@ drawable/button_state1" />
</ selector>
我setBackgroundResource屬性測試,但不起作用。
如何將此佈局分配給Imageview?
在此先感謝。
,並確保它在你的文件夾繪製的,而不是你的佈局文件夾。 – kcoppock 2011-01-06 14:04:45
StateListDrawable修復我的問題,謝謝dtmilano! 對於有同樣問題的用戶,我在下面的文章中留下了代碼 – seba123neo 2011-01-06 14:13:36