Creating an empty Drawable in Android

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.


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


<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> 

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

Tags:

Android