Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setCompoundDrawables with RemoteViews

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

like image 260
Ran Avatar asked Mar 22 '12 09:03

Ran


2 Answers

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)

like image 92
Ran Avatar answered Nov 14 '22 19:11

Ran


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.

like image 1
Wangchao0721 Avatar answered Nov 14 '22 17:11

Wangchao0721