How to disable a button on an appwidget? | Hello Android - 0 views
-
RemoteViews can't manipulate a buttons enabled/disabled state, but it can modify its visibility. So the trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.
-
<Button android:id="@+id/startButton" android:text="Start" android:visibility="visible"></Button> <Button android:id="@+id/startButton_disabled" android:text="Start" android:clickable="false" android:textColor="#999999" android:visibility="gone"></Button> <Button android:id="@+id/stopButton" android:text="Stop" android:visibility="gone"></Button> <Button android:id="@+id/stopButton_disabled" android:text="Stop" android:clickable="false" android:textColor="#999999" android:visibility="visible"></Button>
-
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget); remoteView.setViewVisibility(R.id.startbutton, View.GONE); remoteView.setViewVisibility(R.id.startbutton_disabled, View.VISIBLE); remoteView.setViewVisibility(R.id.stopbutton, View.VISIBLE); remoteView.setViewVisibility(R.id.stopbutton_disabled, View.GONE); AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteView);
- ...1 more annotation...