Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a custom Drawable and use it in XML

Tags:

I am busy creating a less complicated version of NinePatchDrawable that tiles the inner panels instead of stretching them.

I can implement the actual logic to do the rendering and such.

However, I can't find documentation about how to use this Drawable in the XML files. Is this possible? That is, can I have a <tileable-nine-patch>, or some such, tag I can use to define resources?

like image 210
JPvdMerwe Avatar asked Jan 26 '12 13:01

JPvdMerwe


People also ask

How do I make my own drawable?

in Drawable folder of res in project directory, make xml file and name it as layerlist. xml and paste it below code as your requirement. you can also add your shape drawable instead of drawable in the <item/> tag in the example. and use this xml as a background of ImageView .

What is xml drawable?

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.

How do I add an image to a drawable XML file?

Step 1: In this method first of all in your system find your required images and copy the image as we do normally. Step 2: Then open the Android Studio go to the app > res > drawable > right-click > Paste as shown in the below figure. Step 3: Then a pop-up screen will arise like below.


1 Answers

Unfortunately it is not possible to use custom drawables in XML files (for API 23 and below) due to potential security issues. See here for a Google Groups thread about this very topic with a response from Romain Guy, one of the Android developers.

You can still use them in your Java code though.

Update:

As LeoFarage points out in the comments, starting in API 24 you can now use custom drawables in XML files but only within your application package.

like image 83
Charles Harley Avatar answered Oct 15 '22 22:10

Charles Harley