onOptionsItemSelected not called when using actionLayout (SherlockActionBar)

前端 未结 6 1076
误落风尘
误落风尘 2020-12-01 07:39

The method onOptionsItemSelected isn\'t being called when using actionLayout in a menu item. Am I missing something, or is it a known problem with SherlockActionBar?

6条回答
  •  独厮守ぢ
    2020-12-01 07:48

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.main, menu);
        View view = menu.findItem(R.id.menu_item_comment).getActionView();
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // do something
            }
        });
        return true;
    }
    

    Also, (and that was very important for me, so other answers did not work) you need to disable the clickable option of all views in your action layout (that is, action_bar_comment_layout.xml):

    android:clickable="false"
    

提交回复
热议问题