0
我創建了自定義視圖並繪製了位圖圖像。如何我在widget..Below使用該視圖是代碼在窗口小部件中使用視圖
public class MyWidget extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for(int i=0 ; i<appWidgetIds.length; i++) {
int appWidgetId = appWidgetIds[i];
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
views.setImageViewBitmap( ...);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
public class myCustomView extends View {
Bitmap img;
public myCustomView(Context context) {
super(context);
img = BitmapFactory.decodeResource(context.getResources(), R.drawable.myimg);
}
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(img, 0, 0, new Paint());
}