在“选项”菜单上切换 Wifi 状态
我想在 Android 的选项菜单中切换 Wifi 的状态。我想通过显示两个图标来扩展其功能,一个表示“打开”,另一个表示“关闭”。它应该以这样的方式工作:当用户按下菜单键时:
- 他应该看到 Wifi 的当前状态“打开”或“关闭”
- 图标必须根据其状态“打开”或“关闭”显示
- 当用户单击时Wifi 选项应该切换 Wifi 的状态并相应地更改图标
这可以在选项菜单中执行吗?
关于如何根据其状态更改图标有什么想法吗?
到目前为止,我可以通过将用户带到不同的活动来切换 Wifi 状态。但如果我可以在选项菜单中实现它。这将使该应用程序更易于使用。
感谢您的投入和宝贵的时间。
I would like to toggle the state of Wifi in options menu in Android. I would like to extend its functionality by showing two icons one for "switched on" and the other for "switched off". It should work in such a way that when a user presses the menu key:
- He should see current status of Wifi "on" or "off"
- The icons must be shown according to its state "on" or "off"
- When the user clicks the Wifi option it should toggle the state of Wifi and also change the icon accordingly
Is this possible to do in the options menu ?
Any ideas as to how to change the icons according to its state ?
So far I am able to toggle the Wifi state by taking the user to a different activity. But if I can achieve it in the options menu. It would make the app more easy to use.
Thank you for your input and for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里是 wifi 开/关的代码:
}
manifest.xml(添加权限)
menu.xml 文件:
here is the code for wifi on/off :
}
manifest.xml (add permission)
menu.xml file :