Search code examples
javaandroidvector

set vector drawable to side drawable in textview in Android


I have a vector drawable which I want to set to textview sides Drawable. after some googling some people suggesting to put my vector drawable in layerList then set layer list drawable to textview drawables and now my code is:

layerList:

<?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> 

get drawable in java:

 Drawable ArrowDrawable = AppCompatResources.getDrawable(this, R.drawable.selected_arrow);     

when I run my code on Android 6 devices it works fine but when I run it On Android 4.4 I got this error message:

 android.content.res.Resources$NotFoundException: File res/drawable/selected_arrow.xml from drawable resource ID #0x7f0200c1

can anybody help about this problem?
UPDATE
my problem is not to use vector drawable's in lower than Android 5 because I use them right now with appcompatImageviews and works fine my problem is getting vector drawable and set them to textview drawable's in java so this link do not help me.


Solution

  • Thanks for you'r attention but this question don't help me.
    but after some googling I found about vector drawable's that I have to add this line

     static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }       
    

    to my activity and now my app works fine