AppWidgetProvider如何更改背景onclick按钮?

时间:2013-03-22 10:07:56

标签: android android-widget appwidgetprovider

我有这段代码

public class SMWidget extends AppWidgetProvider {

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIDs) {
    RemoteViews views;      
        views = new RemoteViews(context.getPackageName(), R.layout.smw_layout);

        Intent intent1 = new Intent(context, Receiver.class);
        intent1.putExtra("intent", "1");
        PendingIntent fstpendingIntent = PendingIntent.getBroadcast(context, 0,intent1, 0);
        views.setOnClickPendingIntent(R.id.box1, fstpendingIntent);

        Intent intent2 = new Intent(context, Receiver.class);
        intent2.putExtra("intent", "2");
        PendingIntent sndpendingIntent = PendingIntent.getBroadcast(context, 1, intent2, 0);
        views.setOnClickPendingIntent(R.id.box2, sndpendingIntent);
                    for (int appWidgetID : appWidgetIDs) {
        appWidgetManager.updateAppWidget(appWidgetID, views);
    }
}

我想改变onclicklisntener按钮的设计,我试试这个

Button btn1 = (Button) findViewById(R.id.box1);

但它说“方法findViewById(int)未定义”

请帮助..

0 个答案:

没有答案