禁用button的方法
在AppWidget开发中我们可以使用button,但是却不能是buttondisable为什么呢
RemoteViews不能控制一个button可用和不可用的状态,但是可以控制它的显示与隐藏
因为我们可以利用这个造假然后呢
<ButtonAndroid:idButtonAndroid:id="@+id/startbutton" android:text="Start" android:visibility="visible"> </Button> <Buttonandroid:idButtonandroid:id="@+id/startbutton_disabled" android:text="Start" android:clickable="false" androidandroid:textColor="#999999" android:visibility="gone"> </Button> <Buttonandroid:idButtonandroid:id="@+id/stopbutton" android:text="Stop" android:visibility="gone"> </Button> <Buttonandroid:idButtonandroid:id="@+id/stopbutton_disabled" android:text="Stop" android:clickable="false" androidandroid:textColor="#999999" android:visibility="visible"> </Button>
当点击startbutton的时候
RemoteViews remoteView=newRemoteView(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);
当点击stopbutton的时候
RemoteViewsremoteView=newRemoteViews(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的隐藏转换造成了视觉的欺骗
相关推荐
VitaLemon 2020-10-17
北京老苏 2020-08-17
一像素 2020-08-16
yfisaboy 2020-07-28
preserve log:勾选,页面发生跳转,接口不丢失;;Disable cache:不使用缓存,勾选,拿服务器的缓存;不勾选,用本地缓存;;All那列,表示浏览器的请求类型,对应下面的列type;
baynkbtg 2020-07-05
dingqinghu 2020-06-16
deadgrape 2020-06-09
liujia 2020-06-02
牵手白首 2020-06-02
kikaylee 2020-05-31
MaureenChen 2020-05-25
delmarks 2020-05-17
王磊的程序员之路 2020-05-15
STPace 2020-05-07
singer 2020-05-07
e度空间 2020-04-30
furongwei 2020-04-25