0

Cant change the android:background from my widget_main.xml

I have tryed

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

and

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

with no results.

Here is my 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"/>

and my onReceive from my AppWidgetProvider:

@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); 
Santi Barbat
  • 2,097
  • 2
  • 21
  • 26
  • I guess you should iterate view one by one and set the proper image for every. – Stan Feb 10 '14 at 17:15
  • In onUpdate method it works, with iterate. But, i want to change the background image in OnReceive method.. how can iterate there? Thanks – Santi Barbat Feb 10 '14 at 18:02

0 Answers0