android - 在代码中使用资源中的 VectorDrawable

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

想问一下。从资源中使用 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

最佳答案

关于android - 在代码中使用资源中的 VectorDrawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42317465/

相关文章:

android - 评价应用 URL - 正式版与封闭版

android - 如何使用BottomSheetDialog?

android - 如何从 fragment 场景中获取 fragment 实例

android - API 16 设备上的 fitsSystemWindows 不工作

android - android apk 中的 protobuf.meta 是什么?

android - 如何在android中画一条圆线

android - 按钮包含图像时无法调整位置

ImageButton 颜色不改变 onPressed(), onFocus()

android - 如何在 Android 中验证 SQL 查询

android - ViewPager 的自定义页面可绘制对象