【问题标题】:Using VectorDrawable from resources in code [duplicate]在代码中使用资源中的 VectorDrawable [重复]
【发布时间】:2017-02-18 16:07:46
【问题描述】:

想问。从资源中使用 VectorDrawable 的正确方法是什么? 带有支持库compile 'com.android.support:support-v4:25.1.1'

因为 getDrawable() 已被弃用,当我使用ContextCompat.getDrawable(this, R.drawable.ic_cancel_button); 设置工具栏导航图像时

if(toolbar != null)
{
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_cancel_button));
}

发生错误。

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_cancel_button.xml from drawable resource ID #0x7f02005e

【问题讨论】:

  • 你可以使用这个:ResourcesCompat.getDrawable(getResources(), R.drawable.your_drawable, null)

标签: android android-support-library android-drawable android-appcompat android-vectordrawable


【解决方案1】:

【讨论】:

  • 除此之外别无他法?
  • 我不知道。
  • @Twinkle_Monkey,我想知道它为什么不能满足你的需求?
  • 它实际上可以工作,但几乎没有编辑,就像这样:AppCompatDrawableManager.get().getDrawable(@NonNull Context context, @DrawableRes int resId)
  • @Selvin,这是目前通过框架可用的建议方式。您的评论还应暗示提出更好的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
  • 2017-10-30
相关资源
最近更新 更多