How to define a drawable shape.
File path: res/drawable/filename.xml
Resource type: GradientDrawable
<?xml version="1.0" encoding="utf-8"?> | |
<!-- We are using shape "ring", we have to write extra three attributes as below --> | |
<!-- android:innerRadius, android:thickness, android:useLevel(Must be false) --> | |
<shape | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape=["rectangle" | "oval" | "line" | "ring"] | |
android:innerRadius="intger" | |
android:thickness="intger" | |
android:useLevel="false" > | |
<!-- The corner of the shape --> | |
<!-- android:randius 設置4個角的圓角半徑,但會被特定的圓角設定覆蓋 --> | |
<!-- android:bottomLeftRadius 左下角的圓角半徑 --> | |
<!-- android:bottomRightRadius 右下角的圓角半徑 --> | |
<!-- android:topLeftRandius 左上角的圓角半徑 --> | |
<!-- android:topRightRadius 右上角的圓角半徑 --> | |
<corners | |
android:radius="integer" | |
android:topLeftRadius="integer" | |
android:topRightRadius="integer" | |
android:bottomLeftRadius="integer" | |
android:bottomRightRadius="integer" /> | |
<!-- The corner of the shape --> | |
<gradient | |
android:angle="integer" | |
android:centerX="integer" | |
android:centerY="integer" | |
android:centerColor="integer" | |
android:endColor="color" | |
android:gradientRadius="integer" | |
android:startColor="color" | |
android:type=["linear" | "radial" | "sweep"] | |
android:useLevel=["true" | "false"] /> | |
<padding | |
android:left="integer" | |
android:top="integer" | |
android:right="integer" | |
android:bottom="integer" /> | |
<size | |
android:width="integer" | |
android:height="integer" /> | |
<!-- Fill up the color --> | |
<solid | |
android:color="color" /> | |
<!-- The edge of the shape --> | |
<!-- android:dashGap 虛線間距,這裡設置為0則顯示的為實線 --> | |
<!-- android:dashWidth 虛線寬度 --> | |
<stroke | |
android:width="integer" | |
android:color="color" | |
android:dashWidth="integer" | |
android:dashGap="integer" /> | |
</shape> |