Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:11:01+00:00 2026-05-28T00:11:01+00:00

I would like to toggle the state of Wifi in options menu in Android.

  • 0

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:

  1. He should see current status of Wifi “on” or “off”
  2. The icons must be shown according to its state “on” or “off”
  3. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:11:02+00:00Added an answer on May 28, 2026 at 12:11 am

    here is the code for wifi on/off :

     @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.wifistate:
            final WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            if(wifi.isWifiEnabled()){
                wifi.setWifiEnabled(false);
                Drawable drawable = getResources().getDrawable(R.drawable.off);
                item.setIcon(drawable);
            }else{
                Drawable drawable = getResources().getDrawable(R.drawable.on);
                item.setIcon(drawable);
                wifi.setWifiEnabled(true);
            }
            break;
    
        }
        return true;
    

    }

    manifest.xml (add permission)

    <uses-permission
        android:name="android.permission.ACCESS_WIFI_STATE" />
    

    menu.xml file :

    <?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"><item android:id="@+id/wifistate"  android:title="Off" android:icon="@drawable/off"/></menu>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to 'toggle' the list of options in a select box. I
I would like to toggle the display row for a table in javascript. How
I would like the button on my web page to toggle the visibility of
I would like to programmatically check the value of, and be able to toggle
I would like to know if there is any possibility to turn wifi on
I would like to create a toggle button in my iPhone application. However, I
I would like to create a custom button, that has two states pressed or
I would like the toggle the visibility of a ListBox by tapping on a
In the app I've been working on, I would like to have a multiple-state
I have jscript to toggle divs to slide up and down. I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.