setCompoundDrawables с RemoteViews - PullRequest
       3

setCompoundDrawables с RemoteViews

7 голосов
/ 22 марта 2012

У меня есть макет appwidget с textview и imageview.

Lint всегда говорит мне заменить его на составное textview.

Проблема в том, как я могу вызвать setCompoundDrawables сRemoteViews?возможно ли это?

спасибо.

ОБНОВЛЕНИЕ: http://code.google.com/p/android/issues/detail?id=29249

Ответы [ 3 ]

6 голосов
/ 27 июня 2012

Эта опция была добавлена ​​в API Level 16 (Android 4.1 Jellybean):

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

1 голос
/ 26 июня 2012

Когда вы используете 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.

0 голосов
/ 13 сентября 2017

использовать setTextViewCompoundDrawables

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