动画ActionButton不会触发click事件

时间:2017-06-08 03:38:33

标签: android android-animation animator action-button

我正在设置动作按钮的动画:

@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);
}

但问题是,应用此动画后,点击事件并未触发此事件。我错过了什么?

1 个答案:

答案 0 :(得分:0)

我认为你应该将该代码放在

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

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

不在

onCreateOptionsMenu()