Android MenuItem Toggle Button

后端 未结 2 1019
不知归路
不知归路 2020-12-06 07:12

In my Android application, I want a setting to be toggleable in it\'s menu like the Dialer app does for speaker and mute. You can see a picture below:

http://www.i

相关标签:
2条回答
  • 2020-12-06 07:35

    It's looks like this menu item is implemented as a custom view.

    In the android source code you can take a look at com.android.phone.InCallMenuView.java to see how this is implemented.

    It doesn't look like it is part of the public API, but it looks pretty self-contained. If your project has a compatible license, you may be able to copy it into your project and use and modify it as you see fit.

    0 讨论(0)
  • 2020-12-06 07:55

    You could do something like the snippet below as well, originally sourced from anddev.org

    public boolean onPrepareOptionsMenu(final Menu menu) {       
          if(super.mMapView.isTraffic()) 
               menu.findItem(MENU_TRAFFIC_ID).setIcon(R.drawable.traffic_off_48); 
          else 
               menu.findItem(MENU_TRAFFIC_ID).setIcon(R.drawable.traffic_on_48); 
    
          return super.onPrepareOptionsMenu(menu); 
     }
    
    0 讨论(0)
提交回复
热议问题