我正在开发一个按钮小部件,当用户单击我想更改资源图像的按钮时,它不起作用,有我的代码:
小部件.xml:
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="center" >
<ImageButton
android:id="@+id/widgetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:src="@drawable/android_widget"
android:clickable="true"
android:contentDescription="@string/widget_image"
/>
</FrameLayout>
MyWidgetActivity.java :
public class MyWidgetActivity extends Activity implements ExceptionHandler {
RemoteViews remoteViews;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Get the remoteViews view
remoteViews = new RemoteViews(this.getPackageName(), R.layout.widget);
// Change the remoteViews button clicked style
remoteViews.setInt(R.id.widgetButton, "setImageResource",
R.drawable.android_widget2);
}
}
谢谢你。