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
I use an empty ShapeDrawable
, i.e. create my own drawable/empty.xml containing just <shape/>
Kai, I don't know why this is the case, but I've gotten the same issue. I think it might be related to the version of Android you're compiling for? In any case, I found that simply using @android:id/empty where you would use @android:drawable/empty does the trick.
<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.
@null
in XML has the same effect as using a null
as a Drawable
in Java.