7

I have an appwidget layout with a textview and an imageview.

Lint always tells me to replace it with a compound textview.

The problem is, how do I call setCompoundDrawables with a RemoteViews? is it possible?

thanks.

UPDATE: http://code.google.com/p/android/issues/detail?id=29249

Ran
  • 4,117
  • 4
  • 44
  • 70
  • I can't recollect how I did it or whether it is relevant, but once I'd annotated a method as "@Remotable" and was able to invoke it later. Not sure if it can help in this case. Otherwise, I don't see any other way it can be done. – Dheeraj Vepakomma Apr 03 '12 at 18:38

3 Answers3

6

This option was added in API Level 16 (Android 4.1 Jellybean):

http://developer.android.com/reference/android/widget/RemoteViews.html#setTextViewCompoundDrawables(int, int, int, int, int)

gopi1410
  • 6,567
  • 9
  • 41
  • 75
Ran
  • 4,117
  • 4
  • 44
  • 70
1

When you use setCompoundDrawables , you need code like :

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); 

So you must have ways to call getResources()! You can pass Activity context as a param to use getResources() & findViewById.

Wangchao0721
  • 909
  • 1
  • 9
  • 23
  • 3
    getResources is not the problem. RemoteViews doesn't have setCompoundDrawables method. My current answer is that it's not possible. maybe in jellybean.. – Ran Jun 27 '12 at 09:18
0

use setTextViewCompoundDrawables

contentiew.setTextViewCompoundDrawables(R.id.setting_btn, 0, R.mipmap.ic_gray_setting,0,0);
Junsu Cho
  • 826
  • 7
  • 16