0

我正在为操作按钮设置动画:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ImageView iv = (ImageView)inflater.inflate(R.layout.iv_main_menu_icon, null);
    Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate);
    rotation.setRepeatCount(Animation.INFINITE);
    iv.startAnimation(rotation);
    menu.findItem(R.id.action_goto_menu).setActionView(iv);
    return super.onCreateOptionsMenu(menu);
}

但问题是,在应用此动画后,单击事件不会由此触发。我错过了什么?

4

1 回答 1

0

我认为您应该将该代码放入

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {

default:
    return super.onOptionsItemSelected(item);
}
}

不在里面

onCreateOptionsMenu()
于 2017-06-08T03:57:36.330 回答