如何在我的Widget中有一个图像,然后当它点击时更改为另一个图像?它是一个只有一个ImageButton的小部件,但是我不知道在这之后去哪里,我知道所有关于待定意图等等,但这在这里没有用,除非我遗漏了什么......这是我的onUpdate
public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds){
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
PendingIntent onPendingIntent = PendingIntent.getService(context, 0, new Intent(context, widgetService.class), 0);
remoteViews.setOnClickPendingIntent(R.id.ImageButton01, onPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}
答案 0 :(得分:5)
我认为这就是你要找的东西
/* get the handle on your widget*/
RemoteViews views = new RemoteViews(getPackageName(), R.layout.your_widget_layout);
/* replace the image */
views.setBitmap(R.id.id_of_your_imageview, "setImageBitmap", yourBitmap);
/* update your widget */
ComponentName thisWidget = new ComponentName(this, YourWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, updateViews);
答案 1 :(得分:1)
试试这个:
public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds){
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
PendingIntent onPendingIntent = PendingIntent.getService(context, 0, new Intent(context, widgetService.class), 0);
remoteViews.setOnClickPendingIntent(R.layout.widget2, onPendingIntent);
**add widgetON.xml*
为“widgetON”图像设置单独的.xml布局。 (WIDGET2) 然后,你必须弄乱remoteViews来区分ON / OFF视图
我想。 :D