Creating an empty Drawable in Android

Creating a Drawable that is completely empty seems like a common need, as a place holder, initial state, etc., but there doesn't seem to be a good way to do this... at least in XML. Several places refer to the system resource @android:drawable/empty but as far as I can tell (i.e., it's not in the reference docs, and aapt chokes saying that it can't find the resource) this doesn't exist.

Is there a general way of referencing an empty Drawable, or do you end up creating a fake empty PNG for each project?


For me it didn't work when I tried to use @android:id/empty when making an empty drawable. For me, @android:color/transparent was the one.


I use an empty ShapeDrawable, i.e. create my own drawable/empty.xml containing just <shape/>


<shape />

creates an empty shape and does the trick for me. Or create a file empty_drawable.xml containing:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" />

so you can use it elsewhere.

You can also make a shape disappear when the view it is used in is not enabled by creating my_disablable_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="true">
        <shape android:shape="oval">
            <size android:height="10dp" android:width="10dp" />
            <solid android:color="@android:color/white" />
        </shape>
    </item>
    <item android:state_enabled="false">
        <shape />
    </item>
</selector> 

Use @android:color/transparent and don't forgot add android:constantSize="true" on <selector>


For me, using @android:drawable/empty would show an error and prevent compiling. Using @android:id/empty fixed the error and let me compile, but showed "NullPointerException: null" in the Eclipse Layout editor. I changed it to @android:color/transparent and now everything is fine.

I can't vote up yet or I would have up'ed Emil's answer.