在 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的隐藏转换 造成了视觉的欺骗

更多相关文章

  1. 72、android状态栏一体化,状态栏改变颜色
  2. Android控件ToggleButton多状态按钮使用详解
  3. Android如何实现5.0以上图片沉浸式状态栏
  4. Android编程获取网络连接状态(3G/Wifi)及调用网络配置界面
  5. android定制状态栏
  6. Android-标题状态栏的隐藏
  7. Android WIFI状态监控
  8. android音乐播放器监听电话状态,解决通话中的音乐的播放

随机推荐

  1. android 网络连接 大体走向
  2. Android(安卓)仿微信对话列表滑动删除效
  3. Ubuntuecplise中连接Android真机…
  4. Android(安卓)Jetpack -- navigation
  5. Android笔记:Android中的使用
  6. 使用 标签来重用layout代码
  7. 最近Android的学习总结
  8. Android二进制工具objdump/readelf不能打
  9. android ethernet移植- freescale i.mx23
  10. You cannot combine custom titles with