Я пытаюсь обновить цвет ImageView
в своем AppWidget
в моем приложении для Android.Обновление Android AppWidget ImageView src с цветом
У меня есть шестнадцатеричный десятичный знак для моего цвета, допустим, #ffffff
.
Я отправляю широковещательную передачу от активности, запуская виджет onReceive
. Цвет сохраняется в SharedPreferences
. Это как AppWidget onReceive()
выглядит следующим образом:
@Override
public void onReceive(Context context, Intent intent) {
RemoteViews widgetView = new RemoteViews(context.getPackageName(),
R.layout.appwidget_homescreen);
AppWidgetManager appWidgetManager = AppWidgetManager
.getInstance(context);
// If the WidgetProvider was told to update the colors of the widget
if (intent.hasExtra("updateTheme")) {
SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(context);
String txtColorString = sharedPref.getString(
PreferencesActivity.KEY_PREF_TXT_COLOR, "");
int txtColor = Integer.parseInt(txtColorString);
//I'm setting the color of the two text views here, working as intended.
widgetView.setTextColor(R.id.tvAppWidgetArtist,txtColor
);
widgetView.setTextColor(R.id.tvAppWidgetTitle,
txtColor);
//I want to set the color of the ImageView here, this is not working.
widgetView.setTextColor(R.id.ivAppWidgetHS, txtColor);
widgetView.setTextColor(R.id.ivAppWidgetVS, txtColor);
appWidgetManager.updateAppWidget(new ComponentName(context,
SongAppWidgetProvider.class), widgetView);
}
super.onReceive(context, intent);
}
Проблема заключается в том, что цвет не обновляется. Все, что он говорит, это «Виджет проблемной загрузки». Любые идеи, почему?
и проблема? – Yazan
@Yazan Проблема в том, что она не работает, я получаю «Проблемный загрузочный виджет» на рабочем столе – Marcus