views:

63

answers:

3

Ok guys I'm little stacked here. According to official documentation Google says that "Once you've defined your Drawable in XML, save the file in the res/drawable/ directory of your project." is the way to add a XML drawable to the project.

But when I created the project ADT created 3 different drawable folders for mdpi, hdpi, and ldpi. So when I wanted to create my XML drawable, I right click on my drawable-hdpi folder and select "Add new Android XML file", and there I have to select what kind of XML file I want to create, but there isn't "drawable" to select.

If I create new text file and save it as button_drawable.xml Eclipse says that there is an Error in the file and that It can't build my project.

So, please tell me how do you add xml drawables in Eclipse ADT?

A: 

I have that problem sometimes.

I always create the XML drawable as "New text file". If you get an error after the XML drawable has been created, check the XML syntax to be sure there is no error in the file, and try to clean the project (Project->Clean->Your project)

Good luck

Antonio
A: 

Drawable is a class within Android, it represents images such a pngs that have been created or loaded from files.

What the documentation meant was added all your images to your drawable folders, then optionally create an xml file that sets the states for the image, by going to File->New->File and typing out the XML yourself. The first link below gives you a template/idea of what it should look like.

Say for example the xml file was custom_button.xml, and you had put in in /res/drawable then in your code, you type R.drawable.custom_button, or if it was just an image such as picture.png then again R.drawable.picture.

XML Drawable

Drawable Class

raybritton
A: 

Just add a new XML file into the res/drawable folder. The drawable file looks like next:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <gradient
        android:startColor="#FF000000"
        android:centerColor="#FF000000"
        android:endColor="#FF777777"
        android:angle="90" />
</shape>
kankan