Menu with action bar sherlock

后端 未结 3 1865
囚心锁ツ
囚心锁ツ 2021-02-05 08:41

I need an example or a tutorial on how to add menu items with action bar sherlock

When I use the simple menu with the imports

import android.view.Menu;
         


        
相关标签:
3条回答
  • 2021-02-05 09:13

    I used @Matt's answer above but ran into problems with onContextItemSelected.

    Basically, you just have to use

    @Override
    public boolean onContextItemSelected(com.actionbarsherlock.view.MenuItem item) {
        /* ... */
    }
    

    instead of

    @Override
    public boolean onContextItemSelected(android.view.MenuItem item) {
        /* ... */
    }
    
    0 讨论(0)
  • 2021-02-05 09:22

    You have to use Menu, MenuInflater and MenuItem classes from com.actionbarsherlock.view package:

    import com.actionbarsherlock.view.Menu;
    import com.actionbarsherlock.view.MenuInflater;
    import com.actionbarsherlock.view.MenuItem;
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.settings_menu, menu);
    
        return super.onCreateOptionsMenu(menu);
    }
    

    BTW, ActionBarSherlock contains a lot of samples.

    0 讨论(0)
  • 2021-02-05 09:26

    I used @StenaviN 's answer above but ran into problems with onContextItemSelected. This post solved it for me.

    Basically, you just have to use

    @Override
    public boolean onContextItemSelected(android.view.MenuItem item) {
        /* ... */
    }
    

    instead of

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        /* ... */
    }
    
    0 讨论(0)
提交回复
热议问题