Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a image to drawable xml in android

Tags:

android

I have a drawable xml file which draws a circle.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid

    android:color="#666666" />

<size
    android:width="120dp"
    android:height="120dp" />
</shape>

now, I have to add a image in drawable folder. please help me where to change the code.

like image 520
kashyap Avatar asked Oct 25 '16 08:10

kashyap


People also ask

Which function is used to load a drawable image resource?

Drawable drawable = ResourcesCompat. getDrawable (res, R. drawable. myimage, null);


1 Answers

You can use a layer list like this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
       <shape android:shape="oval">
           <solid
               android:color="#666666"/>

           <size
               android:width="120dp"
               android:height="120dp"/>
       </shape>
   </item>

   <item android:drawable="@drawable/your_drawable"/>
</layer-list>
like image 162
François Legrand Avatar answered Sep 29 '22 03:09

François Legrand