appwidget中使按钮不能用 以及 appwidget初学指导
16lz
2021-01-23
在 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的隐藏转换 造成了视觉的欺骗
更多相关文章
- 72、android状态栏一体化,状态栏改变颜色
- Android控件ToggleButton多状态按钮使用详解
- Android如何实现5.0以上图片沉浸式状态栏
- Android编程获取网络连接状态(3G/Wifi)及调用网络配置界面
- android定制状态栏
- Android-标题状态栏的隐藏
- Android WIFI状态监控
- android音乐播放器监听电话状态,解决通话中的音乐的播放