我尝试使用AnimatedVectorDrawable访问ContextCompat,如下所示。我使用下面的代码来做到这一点。它在5和更高版本中运行良好,但在4中却不起作用。
@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
我怎么能解决这个问题?
发布于 2016-10-18 08:33:51
试试这个:AnimatedVectorDrawableCompat.create(this, R.drawable.animated_vector_name)
https://stackoverflow.com/questions/40103290
复制相似问题