Search code examples
androidandroid-drawable

How to use > and /> in Android drawables?


Which items in drawables in Android should be closed with > and which ones should be closed with />?


Solution

  • When you define any tag's attribute and want to add some child tags is close with '>' and when you want to end any tag without any child tags you should use '/>'

    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white" />
    
    <stroke
        android:width="1dp"
        android:color="@color/white" />
    
    <padding
        android:bottom="1dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp" />
    
    <corners android:radius="@dimen/_5sdp" />
    </shape>
    

    Here <shape xmlns:android="http://schemas.android.com/apk/res/android"> have child tags so it ended with '>' and tag closed as </shape>

    and <solid android:color="@color/white" /> haven't any child tag so it ended with '/>' and ended.