actionbar menu item onclick?

后端 未结 2 1383
傲寒
傲寒 2020-12-31 09:45

I have an action bar that puts everything in a menu in the top right, which the user clicks and the menu options open up.

I inflate the action bar menu with this on

2条回答
  •  悲&欢浪女
    2020-12-31 10:13

    If you add an onClick attribute on your menu item like this:

    
    
        
    
    
    
    
    

    Then in your activity:

    public void doThis(MenuItem item){
        Toast.makeText(this, "Hello World", Toast.LENGTH_LONG).show();
    }
    

    Note:

    ActionBarSherlock is deprecated. Unless you are developing an app for Android 4.0 or older, please don't use it. But if you are using the library, you will have to import

    import com.actionbarsherlock.view.MenuItem;

    and not

    import com.android.view.MenuItem;

    In addition, you could do something like this: ActionBar Sherlock Menu Item OnClick

    which @adneal mentions.

提交回复
热议问题