动画ActionBarDrawerToggle图标编程 [英] Animate ActionBarDrawerToggle icon programmatically

查看:184
本文介绍了动画ActionBarDrawerToggle图标编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从汉堡抽屉图标,动画一个箭头,反之亦然手动,不仅当抽屉被拖动,这可能吗?我使用的是支持库appcompat-V7:21。

I want to animate the drawer icon from a burger to an arrow and vice versa manually, not only when drawer is being dragged, is it possible? I'm using support library appcompat-v7:21.

另外,我找不到android.support.v7.app.ActionBarDrawerToggle源$ C ​​$ C这将有所帮助。

Also I can't find the source code of android.support.v7.app.ActionBarDrawerToggle which would helpful.

推荐答案

我找到了一种方法来制作具有简单ValueAnimator图标和 .onDrawerSlide 方法。

I found a way to animate the icon with a simple ValueAnimator and .onDrawerSlide method.

    ValueAnimator anim = ValueAnimator.ofFloat(start, end);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float slideOffset = (Float) valueAnimator.getAnimatedValue();
            drawerToggle.onDrawerSlide(drawerLayout, slideOffset);
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(300);
    anim.start();

不过,也许有更好的解决方案。

But maybe there is a better solution.

这篇关于动画ActionBarDrawerToggle图标编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆