看看这个图书馆:
https://github.com/wnafee/vector-compat
它提供了AnimatedVectorDrawable和MorphButton,它可以完全满足您的需求.
说明
1 – 将vector-compat依赖项添加到build.gradle文件中,并确保使用buildToolsVersion 22或更高版本:
android {
// use version 22 or higher
buildToolsVersion "22.0.1"
...
}
dependencies {
compile 'com.wnafee:vector-compat:1.0.5'
...
}
2 – 在布局xml中添加MorphButton视图
android:id="@+id/playPauseBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:vc_startDrawable="@drawable/ic_pause_to_play"
app:vc_endDrawable="@drawable/ic_play_to_pause" />
要在您的应用中使用MorphButton,请确保在您的基本应用主题中包含morphButtonStyle项:
@style/Widget.MorphButton
用于播放/暂停和播放/停止的动画矢量绘图已经包含在库中,因此上面的代码开箱即用,您不需要自己导入任何额外的drawable.