android中利用shape构造的图片时,经常会用一个图片配N个颜色,并且shape是静态,如果要使用多个颜色的shape,静态写多个shape的文件是非常不好的,那可不可以动态改变shape的背景颜色而不变化基本形状呢?
当然是可以的啦
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radiusTopLeft="4dp"
android:radiusTopRight="4dp"
android:radiusBottomLeft="7dp" android:radiusBottomRight="7dp" />
<solid android:color="#fafafa" />
</shape>
GradientDrawable drawable =(GradientDrawable)view.getBackground();
drawable.setColor(getResources().getColor(R.color.facfcf));