首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getDrawable与AnimatedVectorDrawable在android 4中崩溃

getDrawable与AnimatedVectorDrawable在android 4中崩溃
EN

Stack Overflow用户
提问于 2016-10-18 08:31:10
回答 1查看 871关注 0票数 0

我尝试使用AnimatedVectorDrawable访问ContextCompat,如下所示。我使用下面的代码来做到这一点。它在5和更高版本中运行良好,但在4中却不起作用。

代码语言:javascript
复制
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void startOpenAnimations() {

        // Icon
        AnimatedVectorDrawable menuIcon = (AnimatedVectorDrawable) ContextCompat.getDrawable(getContext(),
                R.drawable.ic_menu_animated);
        mFabView.setImageDrawable(menuIcon);
        menuIcon.start();

        // Reveal
        int centerX = mFabRect.centerX();
        int centerY = mFabRect.centerY();
        float startRadius = getMinRadius();
        float endRadius = getMaxRadius();
        Animator reveal = ViewAnimationUtils
                .createCircularReveal(mNavigationView,
                        centerX, centerY, startRadius, endRadius);

        // Fade in
        mNavigationMenuView.setAlpha(0);
        Animator fade = ObjectAnimator.ofFloat(mNavigationMenuView, View.ALPHA, 0, 1);

        // Animations
        AnimatorSet set = new AnimatorSet();
        set.playSequentially(reveal, fade);
        set.start();
    }

来自可绘制资源ID的android.content.res.Resources$NotFoundException:文件res/ drawable /ic_menu_activated.xml 0x7f020064 在android.content.res.Resources.loadDrawable(Resources.java:3451) at android.content.res.Resources.getDrawable(Resources.java:1894) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)

为什么在棒棒糖设备中不可能使用getDrawable和ContextCompat

我怎么能解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-18 08:33:51

试试这个:AnimatedVectorDrawableCompat.create(this, R.drawable.animated_vector_name)

参考资料:https://stackoverflow.com/a/35699072/7001152

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40103290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档