Android 主屏幕小部件中的 ImageButton
我有一个带有图像按钮的主屏幕小部件。我让按钮以待处理的意图工作,但我似乎不知道如何在按下按钮时更改按钮图像。
我尝试使用选择器,它在我的小部件测试活动中有效,但在远程视图中无效。
如何在主屏幕小部件中实现此功能?
I have a homescreen widget with an imagebutton. I have the button working with a pending intent, but I can't seem to figure out how to change the button image when it is pressed.
I tried using a selector and it works in my widget test activity, but not in the remoteview.
How could I implement this functionality in the home screen widget?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在远程视图中设置不同的图像。
You can set a different Image within your remote view.
我能够通过将选择器移动到它自己的 XML 文件中并放入 res/drawable 中,然后引用该 xml 文件作为应用程序小部件的布局 xml 中的图像按钮的资源来使其工作。
buttonimg.xml:
widget_layout.xml
但是,我现在遇到了不同的问题。选择器只允许我在按下时更改图像。释放时,图像变回>:-(
如何在按下时获得图像状态更改并保持该状态直到下次按下(如切换按钮)?
I was able to get it working by moving the selector inside it's own XML file and putting in res/drawable and then referencing that xml file as my resource for my imagebutton in the app-widget's layout xml.
buttonimg.xml:
widget_layout.xml
I now have a different problem, however. The selector only allows me to change the image onPress. On release, the image changes back >:-(
How do I get the image state change on press and stay in that state until next press (like the ToggleButton)?