1 shape
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle|oval|line|ring"
xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:radius=""
android:topLeftRadius=""
android:topRightRadius=""
android:bottomLeftRadius=""
android:bottomRightRadius=""
/>
<gradient
android:angle=""
android:centerX=""
android:centerY=""
android:startColor=""
android:centerColor=""
android:endColor=""
android:gradientRadius=""
android:type="linear|radial|sweep"
android:useLevel="true|false"
/>
<padding
android:top=""
android:left=""
android:right=""
android:bottom=""
/>
<size
android:width=""
android:height=""
/>
<solid
android:color=""
/>
<stroke
android:width=""
android:color=""
android:dashWith=""
android:dashCap=""
/>
</shape>
2 LayerDrawable用于progressDrawable
progress——drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="90dp" />
<solid android:color="#ffffff"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="90dip" />
<gradient
android:angle="270"
android:centerColor="#C6B7FF"
android:centerY="0.75"
android:endColor="#C3B2FF"
android:startColor="#B9A4FF" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="90dp" />
<gradient
android:angle="0"
android:endColor="#df0024"
android:startColor="#de4e2c" />
</shape>
</clip>
</item>
</layer-list>
progressbar的背景,padding=2dp之内填充progressdrawable,外面形成2dp的的边框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark"/>
<corners android:radius="90dp"/>
<solid android:color="#cecece"/>
<padding
android:bottom="2dp"
android:top="2dp"
android:left="2dp"
android:right="2dp"
/>
</shape>
3 stateList也就是selector
4LevelListDrawable
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_gray" android:maxLevel="0" />
<item android:drawable="@drawable/shape_login" android:maxLevel="1"/>
</level-list>
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/collapse" android:maxLevel="0" />
<item android:drawable="@drawable/expanded" android:maxLevel="1"/>
</level-list>
<ImageView
android:id="@+id/iv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="100dp"
android:background="@drawable/level_drawable_bg"
android:src="@drawable/level_drawable"
app:layout_constraintTop_toTopOf="parent" />
iv.setImageLevel(level);//切换前景图
LevelListDrawable levelListDrawable= (LevelListDrawable) iv.getBackground();
levelListDrawable.setLevel(level);//切换背景图
4TransitionDrawable
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_gray" />
<item android:drawable="@drawable/shape_login" />
</transition>
TransitionDrawable transitionDrawable = (TransitionDrawable) tv.getBackground();
transitionDrawable.startTransition(1000);