重置视图的按下状态

3
我有一个基于视图的布局(没有片段,只有一个活动),并在不同状态之间进行动画。为了更好的平滑度,我使用了两个工具栏并淡入淡出它们。
问题是,如果我按下一个工具栏的导航按钮并开始淡入淡出动画,则导航按钮不会恢复其未按下状态(可能由于动画),导致选择器不会消失... 当我重新显示此工具栏时,导航按钮看起来被按下(涟漪可绘制仍然可见)。
我能手动清除涟漪动画吗?
我尝试过获取工具栏导航视图,如下所示:获取工具栏导航图标视图引用
  1. I tried clearing the animation of the view: toolbarNavigationView.clearAnimation()
  2. I tried resetting the drawable with ViewCompat.jumpDrawablesToCurrentState(toolbarNavigationView);
  3. I tried posting this to the toolbar to make sure the layout is layed out like following:

    toolbar.post(new Runnable()
    {
        @Override
        public void run()
        {
            ViewCompat.jumpDrawablesToCurrentState(toolbarNavigationView);
        }
    });
    
2个回答

1
此技巧适用于清除具有 android:background="?attr/selectableItemBackground" 属性的视图的触摸动画(在 API 24、支持库 26.0.0 上测试通过):
view.setVisibility(View.INVISIBLE);
view.setVisibility(View.VISIBLE);

0
尝试获取动画并重置它,就像这样:

Animation anim = yourView.getAnimation();
            if (anim != null) {
                yourView.reset();
            }
            yourView.clearAnimation();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接