1

I have a vector drawable wich I want to set to textview sides Drawable. after some googling some pepole 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.

Community
  • 1
  • 1
max
  • 5,963
  • 12
  • 49
  • 80

2 Answers2

1

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

Umair
  • 6,366
  • 15
  • 42
  • 50
max
  • 5,963
  • 12
  • 49
  • 80
0

set vector drawable to side drawable in textview in android

AppCompatTextView now supports app:drawableLeftCompat, app:drawableTopCompat, app:drawableRightCompat, app:drawableBottomCompat, app:drawableStartCompat and app:drawableEndCompat compound drawables, supporting backported drawable types such as VectorDrawableCompat.

Include this in your gradle file

implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'androidx.appcompat:appcompat-resources:1.1.0-beta01'

In your text view you can use

app:drawableLeftCompat
app:drawableStartCompat
Darish
  • 11,032
  • 5
  • 50
  • 70
  • This is still in beta version... and breaks the recyclerview. Amazing how google didn't fix this yet! – Sergio Jun 24 '19 at 09:33