i "estoy tratando de encontrar una manera de cambiar la imagen del botón i fin de mostrar el estado actual de la aplicación.¿Cómo podemos cambiar la imagen de un botón de widget?
esto es lo que he hecho hasta ahora ...
HelloWidgetProvider. java
public class HelloWidgetProvider extends AppWidgetProvider {
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
// TODO Auto-generated method stub
//super.onDeleted(context, appWidgetIds);
Toast.makeText(context, "onDeleted()", Toast.LENGTH_LONG).show();
}
@Override
public void onDisabled(Context context) {
// TODO Auto-generated method stub
//super.onDisabled(context);
Toast.makeText(context, "onDisabled()", Toast.LENGTH_LONG).show();
}
@Override
public void onEnabled(Context context) {
// TODO Auto-generated method stub
//super.onEnabled(context);
Toast.makeText(context, "onEnabled()", Toast.LENGTH_LONG).show();
}
public static String MY_WIDGET_UPDATE = "MY_OWN_WIDGET_UPDATE";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
CharSequence strWidgetText = "App Status";
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.hellowidget_layout);
updateViews.setTextViewText(R.id.widgettext, strWidgetText);
appWidgetManager.updateAppWidget(appWidgetIds, updateViews);
super.onUpdate(context, appWidgetManager, appWidgetIds);
Toast.makeText(context, "onUpdate()", Toast.LENGTH_LONG).show();
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onReceive(context, intent);
// if(MY_WIDGET_UPDATE.equals(intent.getAction())){
Toast.makeText(context, "onReceiver()", Toast.LENGTH_LONG).show();
//}
}
}
<?xml version="1.0" encoding="utf-8"?>
hellowidget_layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/widgettext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="@drawable/icon"
android:text="Test Button"
/>
</LinearLayout>
hellowidgetproviderinfo.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dp"
android:minHeight="72dp"
android:updatePeriodMillis="1000"
android:initialLayout="@layout/hellowidget_layout"
>
</appwidget-provider>
Por favor, ayuda .... Gracias