【问题标题】:Android animate toolbar icon while changing its imageAndroid在更改其图像时动画工具栏图标
【发布时间】:2017-01-08 16:10:26
【问题描述】:

在我的应用程序中,我需要以编程方式更改工具栏按钮的图像,因此我正在使用:

public boolean onCreateOptionsMenu( Menu menu ) {
        getMenuInflater().inflate(R.menu.main_activity_menu, menu);
            toolbarButton = menu.findItem(R.id.action_button);
            return true;
        }

toolbarButton.setIcon(R.drawable.ic_settings);

而且效果很好,问题是它发生得太快了,所以我需要在过渡中添加动画,但我不知道如何向工具栏按钮添加动画。 有人可以帮我吗? 非常感谢!

【问题讨论】:

    标签: android animation android-animation android-toolbar


    【解决方案1】:

    好的,最后感谢 Victorldavila 我设法让它工作,这是我的最终代码:

    View button = toolbar.findViewById(R.id.action_button);
    
    //Remove icon animation
    if (button != null) {
       Animation animation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.fragment_fade_out);
       animation.setStartOffset(0);
       button.startAnimation(animation);
    }
    
    //Add icon animation
    if (button != null) {
       Animation animation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.fragment_slide_in_up);
       animation.setStartOffset(0);
       button.startAnimation(animation);
    }
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      相关资源
      最近更新 更多