Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带有RemoteView的setCompoundDrawables_Android_Android Appwidget - Fatal编程技术网

Android 带有RemoteView的setCompoundDrawables

Android 带有RemoteView的setCompoundDrawables,android,android-appwidget,Android,Android Appwidget,我有一个带有textview和imageview的appwidget布局 Lint总是告诉我用复合textview替换它 问题是,如何使用RemoteView调用setCompoundDrawables? 可能吗 谢谢 更新:使用setCompoundDrawables时,需要以下代码: Drawable img; Resources res = getResources(); img = res.getDrawable(R.drawable.btn_img); //You need to se

我有一个带有textview和imageview的appwidget布局

Lint总是告诉我用复合textview替换它

问题是,如何使用RemoteView调用setCompoundDrawables? 可能吗

谢谢


更新:

使用setCompoundDrawables时,需要以下代码:

Drawable img;
Resources res = getResources();
img = res.getDrawable(R.drawable.btn_img);
//You need to setBounds before setCompoundDrawables , or it couldn't display
img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());
btn.setCompoundDrawables(img_off, null, null, null); 
因此,您必须有方法调用getResources()!
您可以将活动上下文作为参数传递,以使用getResources()&findViewById。

此选项是在API级别16(Android 4.1)中添加的:


使用setTextViewCompoundDrawables

contentiew.setTextViewCompoundDrawables(R.id.setting_btn, 0, R.mipmap.ic_gray_setting,0,0);

我不记得我是怎么做的,也不记得它是否相关,但有一次我将一个方法注释为“@Remotable”,并能够在以后调用它。不确定它在这种情况下是否有帮助。否则,我看不到任何其他方法可以做到这一点。getResources不是问题所在。RemoteView没有setCompoundDrawables方法。我目前的答案是这是不可能的。也许在果冻豆里。。