我有一个 vector 可绘制对象,我想将其设置为 TextView 可绘制对象。经过一些谷歌搜索后,一些人建议将我的 vector 可绘制对象放在 layerList 中,然后将图层列表可绘制对象设置为 TextView 可绘制对象,现在我的代码是:
图层列表:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_sort_up"/> //vector drawable
</layer-list>
在 java 中获取可绘制对象:
Drawable ArrowDrawable = AppCompatResources.getDrawable(this, R.drawable.selected_arrow);
当我在 android 6 设备上运行我的代码时它工作正常但是当我在 android 4.4 上运行它时我收到此错误消息:
android.content.res.Resources$NotFoundException: File res/drawable/selected_arrow.xml from drawable resource ID #0x7f0200c1
有人可以帮忙解决这个问题吗?
更新
我的问题是不使用低于 android 5 的 vector 可绘制对象,因为我现在将它们与 appcompatImageviews 一起使用并且工作正常我的问题是获取 vector 可绘制对象并将它们设置为 java 中的 textview 可绘制对象所以 this链接对我没有帮助。
最佳答案
感谢您的关注,但是this question不要帮我。
但经过一番谷歌搜索后,我发现我必须添加这一行的 vector 可绘制对象
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
我的 Activity ,现在我的应用程序运行良好
关于java - 在android中的textview中将 vector drawable设置为side drawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42049886/