2016-05-17 163 views
1

我想設置圖像資源與絃樂無法解決方法setCompoundDrawablesWithIntrinsicBounds

我有設置setCompoundDrawablesWithIntrinsicBounds的問題,它不斷告訴我

cannot resolve method setCompoundDrawablesWithIntrinsicBounds(android.graphics.drawable.Drawable, 0, 0, 0); 

我已經通過網上查,甚至在計算器,我的實現似乎是正確的,但我無法編譯。

String uri = "drawable/my_drawable_image"; 
int imageResource = getResources().getIdentifier(uri, null, getActivity().getPackageName()); 
Drawable image = getResources().getDrawable(imageResource); 
myTextView.setCompoundDrawablesWithIntrinsicBounds(image, 0 ,0 , 0); 

請問我在做什麼錯?

回答

1

Drawable是一個對象。如果使用setCompoundDrawablesWithIntrinsicBounds的重載版本,該版本需要四個Drawable,則不能將0用於未使用/默認值,但必須通過null。更改

myTextView.setCompoundDrawablesWithIntrinsicBounds(image, 0 ,0 , 0); 

myTextView.setCompoundDrawablesWithIntrinsicBounds(image, null , null , null); 

沒有版本的setCompoundDrawablesWithIntrinsicBounds接受一個Drawable作爲第一個參數和三個int秒。有

setCompoundDrawablesWithIntrinsicBounds (int, int, int, int);以及。在這種情況下,您的代碼將會改變,如

myTextView.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0 ,0 , 0); 
+0

謝謝! .... –

+0

不客氣 – Blackbelt