禁用button的方法
16lz
2021-01-26
在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的隐藏转换造成了视觉的欺骗
更多相关文章
- Android(安卓)点击变样式(变色)。
- Android(安卓)fragment 获取id,findViewById为空
- android点击返回键退出应用的实现
- Android(安卓)Notification 通知栏点击不能跳转
- 【Android】(已更新解决方案)更新SDK版本(25)后,自定义FloatingAction
- Unable to find method 'org.gradle.api.tasks.complie.ComplieO
- 小记 ScrollView 隐藏 里面空间填充后再次设置显示,界面会自动往
- Android数据通信开发与应用(四):实战开发
- Android(安卓)studio如何使用SVN进行版本控制?