我正在尝试使用Strings设置图像资源
设置setCompoundDrawablesWithIntrinsicBounds有问题,它一直告诉我
cannot resolve method setCompoundDrawablesWithIntrinsicBounds( android.graphics.drawable.Drawable, 0, 0, 0);
我已经通过在线检查,即使在stackoverflow上,我的实现似乎也正确,但我无法编译。
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);
拜托,我做错了什么?
答案 0 :(得分:1)
Drawable是一个对象。如果您使用setCompoundDrawablesWithIntrinsicBounds
的重载版本,需要四个Drawable
,则无法通过0
未使用/默认值,但您必须使用空值。改变
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);