Resources $ NotFoundException: The resource is not Drawable

I am trying to dynamically install android: src from inside the LayerList tag.

To do this, I need to access the tag, but it continues to fail:

android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=3 r=0x7f090142} 

Here is an example part of a LayerList:

 <item android:id="@+id/my_item_id" android:left="35dip" android:right="0dip" android:top="0dip" android:bottom="50dip"> <bitmap android:id="@+id/my_bitmap_id" android:gravity="left"/> </item> 

And here is the code:

 Resources r = view.getResources(); Drawable drawable = r.getDrawable(myDrawableId); // it abends on this next line LayerDrawable ld = (LayerDrawable) r.getDrawable(R.id.my_item_id); // this is where I want to set the id of the drawable to use in the bitmap ld.setDrawableByLayerId(myDrawableId, drawable); 

Any help would be greatly appreciated!

+1
source share
1 answer

ok, when you call getDrawable, it needs to refer to one of the drawings in your folders with a choice. I'm not sure what my_item_id is, but if this is an example attempt

 LayerDrawable ld = (LayerDrawable) r.getDrawable(R.drawable.my_item_id); 
+2
source

Source: https://habr.com/ru/post/1497474/


All Articles