用RemoteViews设置setCompoundDrawables

7

我不记得我是怎么做的或者它是否相关,但是有一次我将一个方法注释为“@Remotable”,然后能够在以后调用它。不确定它是否对这种情况有帮助。否则,我看不到其他任何可以完成它的方式。 - Dheeraj Vepakomma
3个回答


1

当您使用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()的方法! 你可以将Activity上下文作为参数传递,以使用getResources()和findViewById。


3
getResources不是问题。RemoteViews没有setCompoundDrawables方法。我的当前答案是这是不可能的。也许在Jellybean上有可能。 - Ran

0

使用 setTextViewCompoundDrawables

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接