`
wang_peng1
  • 浏览: 3899816 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

appwidget中使按钮不能用 以及 appwidget初学指导

阅读更多

在 appwidget中我们可以使用button,但是却不能是button disable 为什么呢

RemoteViews 不能控制一个button可用和不可用的状态,但是可以控制它的显示与隐藏

因为我们可以利用这个造假

<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>

 然后呢

当点击startbutton的时候

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);

 

当点击stop button的时候

RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteView.setViewVisibility(R.id.startbutton, View.VISIBLE);
remoteView.setViewVisibility(R.id.startbutton_disabled, View.GONE);
remoteView.setViewVisibility(R.id.stopbutton, View.GONE);
remoteView.setViewVisibility(R.id.stopbutton_disabled, View.VISIBLE);
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteView);

 

其实通过一个android:clickable="false" ,还有buuton的隐藏转换 造成了视觉的欺骗

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics