0

私のwidget_main.xmlから android:background を変更できません

私は試しました

remoteviews.setInt(R.id.boton, "setBackgroundResource", R.drawable.toggle_on);

remoteviews.setImageViewResource(R.id.boton, R.drawable.toggle_on);

結果なし。

ここに私のwidget_main.xmlがあります:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">

<Button 
    android:id="@+id/boton"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/toggle_off"/>

そして私のAppWidgetProviderからの私のonReceive :

@Override
public void onReceive(Context context, Intent intent) {        
    if (intent.getAction().equals(WIDGET_BUTTON)) {         

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);          
        views.setInt(R.id.boton, "setBackgroundResource", R.drawable.toggle_on); 
4

0 に答える 0