public class MyWidget extends AppWidgetProvider {
/** Called when the activity is first created. */
public static final Uri CONTENT_URI = Uri
.parse("content://com.FMCProvider/items");
final static String ACTION_LOG = "com..MyWidget .LOG_ACTION";
public static final String LOG_ACTION = "com.MyWidget .LOG_ACTION";
@Override
public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
{
Log.d("check","onUpdate");
final int N = appWidgetIds.length; // 설정된 위젯 수만큼 반복
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// 다른 프로세스가 액티비티를 수행할 수 있도록 Pending intent 정의
Intent intent = new Intent(context, MobileVoipWidget.class);
intent.putExtra("MESSAGE", "Bye");
intent.setAction(ACTION_LOG);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// 위젯 레이아웃 RemoteViews 얻기
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
// 레이아웃에 포함된 뷰(버튼)의 클릭이벤트 설정
views.setOnClickPendingIntent(R.id.mobile_widget_button, pendingIntent);
// 위젯 매니저에게 업데이트가 완료되었음을 알림
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public void onReceive(Context context, Intent intent) {
Log.d("check", "onReceive : action=" + intent.getAction());
super.onReceive(context, intent);
String action = intent.getAction();
if(action.equals(ACTION_LOG)){
//요기에서
// xml에 들어있는 버튼에 이미지를 변경시켜주고싶습니다.
}
}
<Button android:id="@+id/mobile_widget_button" style="@style/WidgetTouchButton"
android:layout_width="80dp" android:layout_height="95dp"
android:layout_marginTop="40dip" android:layout_marginBottom="0dip"
android:layout_marginLeft="0dip" android:layout_marginRight="0dip"
android:text="" android:drawableTop="@drawable/widget_ic_fmc_off"
></Button>
버튼에 이미지를 넣어 주었습니다.
하지만 버튼 클릭시에 버튼에 이미지를 변경해주고싶지만
바꿔줄수가 없군요 ㅠㅠ
많은 지도 부탁드립니다.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/btn_action_call_pressed" /> // 버튼이 눌렸을때 이미지
<item
android:state_pressed="false"
android:drawable="@drawable/btn_action_call_normal" /> // normal 할때 이미지
</selector>
이 파일을 drawable 폴더에 넣어 주시고 파일명을 drawalbeTop에 넣어주시면 됩니다~



