[英]Change Icon on onReceive method - widget Android
I developed a widget for Android with the intention of clicking a text widget's icon is changed. 我为Android开发了一个小部件,意图点击文本小部件的图标已更改。 To do this I set the action and I have tried the method OnReceive action. 为此,我设置了操作,并尝试了OnReceive方法。 This is the code: 这是代码:
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_WIDGET_NOTIF)) {
Bundle extras = intent.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
RemoteViews controles = new RemoteViews(context.getPackageName(),
R.layout.widgetcuatroxuno);
controles.setImageViewResource(R.id.btt,
R.drawable.ic_launcher_new);
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, controles);
} else {
super.onReceive(context, intent);
}
}
I know I need AppWidgetManager to update the widget controls, but it failed. 我知道我需要AppWidgetManager来更新小部件控件,但它失败了。 How I can fulfill my purpose? 我怎样才能达到目的? Sorry for my English. 对不起我的英语不好。 Thank you very much for everything. 非常感谢你所做的一切。
RemoteViews control = new RemoteViews(context.getPackageName(),
R.layout.widget);
control.setTextViewText(R.id.textview1, "ExampleText");
ComponentName cn = new ComponentName(context,
ButtonWidget.class);
AppWidgetManager.getInstance(context).updateAppWidget(cn,
control);
This one works in OnReceive(), thanks a lot! 这在OnReceive()中有效,非常感谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.