在 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的隐藏转换 造成了视觉的欺骗
分享到:
相关推荐
使用appWidget启动一个Activity
App Widget 的概念 一个简单的App Widget例子 PendingIntent的使用 RemoteViews的使用 接收来自App Widget的广播 更新App Widget的控件状态
android app widget 使用listview 源码
这是一个在应用中创建属于应用的AppWidget的小demo,功能很简单,希望帮助了解AppWidget的创建流程。
AppWidget的学习Demo,创建了一个简单的桌面widget小窗口,并实现与之互动的功能。
Android之初学Appwidget 详解地址 http://blog.csdn.net/manymore13/article/details/8068680
Android -- AppWidget源码
Appwidget就是手机应用中常常放在桌面(即home)上的一些应用程序,比如说闹钟等。这种应用程序的特点是它上面显示的内容能够根据系统内部的数据进行更新,不需要我们进入到程序的内部去,比如说闹钟指针的摆动等。本...
android的appwidget全面解析及启动运行过程。
android appwidget使用说明及示例程序
Android App Widget 开发,demo实现了一个简单的音乐播放器,详见http://blog.csdn.net/huaxun66/article/details/77880376
图中我用黄色箭头指示的即为AppWidget,一些用户使用比较频繁的程序,可以做成AppWidget,这样能方便地使用。典型的程序有时钟、天气、音乐播放器等。AppWidget 是Android 系统应用开发层面的一部分,有着特殊用途,...
Android应用源码之Android小部件AppWidget.zip
在appWidget启动Service,与Service通讯
appwidget的简单使用
1,widget 基本展示 2,widget点击跳转到activity 3,发送广播事件,更新widget界面
NULL 博文链接:https://hanllove001.iteye.com/blog/1185128
android中appwidget介绍,以及其中原理
AppWidget_FlashLight
AppWidget下getBroadcast的使用