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.
here is the code for wifi on/off :
}
manifest.xml (add permission)
menu.xml file :