Is it possible to Implement Toggle Button in Action Menu Item using Actionbar sherlock in android

后端 未结 4 1886
栀梦
栀梦 2021-02-04 02:30

I have an app, which have toggle button in action menu item, though i\'m using Actionbar Sherlock, I don\'t know, how to place the toggle button in the action menu item. I don\'

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 03:19

    create xml file in menu:

    menu.xml

     
    
       
    
    

    And then navigate to your layout folder make a new xml file and name it switch_layout.xml Here's the code: switch_layout.xml

    
    
     
    
    

    In your MainActivity class copy and paste this code:
    MainActivity.java

     @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    
    switchAB = (Switch)menu.findItem(R.id.switchId)
    .getActionView().findViewById(R.id.switchAB);7
    

    Or follow this link about this stuff

提交回复
热议问题