I'm getting the following error message
android.content.res.Resources$NotFoundException: If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way. See AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.
when im trying to set the following:
view.setBackgroundResource(R.drawable.highlight_background);
or
view.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.highlight_background));
I also tried using AppCompatImage. This happens on a device with Android 4.4.4. I've found another StackOverflow thread which provides to add
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
into a MyApplication class and
vectorDrawables.useSupportLibrary = true
into the build.gradle. But the error still occurs. The drawable consists of the following:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="?attr/colorAccent" />
</shape>
It's just a line to encircle an image. Can anyone help me?
Thanks in advance!
view.setBackgroundDrawable()
is deprecated, use
view.setBackgroundResource(int resId)
instead
For example,
yourview.setBackgroundResource(R.drawable.highlight_background);
and offcourse change your color value like this
android:color="@color/color_defined_in_colors_xml_file"
Hope it will help.
you can use imageView.setImageResource();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With