Make a toggle button to widget

喜你入骨 提交于 2019-12-25 08:04:00

问题


How do I add a button to a widget, not for opening an activity or something?

Just for toggling for example Wi-Fi :) Could it be done by a ImageButton or something like that? I just can't figure out how to add an onClickListener.


回答1:


I have updated my answer now that I understand you are trying to write an AppWidget.

AppWidgets support only a limited set of Views and ToggleButton is not one of them. The list of Views supported by AppWidgets can be found here:

http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

You will have to use an ImageButton and remember its toggled state yourself. You can set it's image source to a different image depending on whether it is toggled or not. See ImageButton for more info:

http://developer.android.com/reference/android/widget/ImageButton.html



来源:https://stackoverflow.com/questions/10668867/make-a-toggle-button-to-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!