xml代碼
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<corners android:radius="5dp" />
<stroke
android:width="1dp"
android:color="@color/questionBankLightPurple" />
</shape>
Java代碼:
獲取得drawable,發(fā)現(xiàn)其實返回的是一個 android.graphics.drawable.GradientDrawable;
/**
* 產(chǎn)生shape類型的drawable
*
* @param solidColor
* @param strokeColor
* @param strokeWidth
* @param radius
* @return
*/
public static GradientDrawable getDrawable(int solidColor, int strokeColor, int strokeWidth, float radius) {
GradientDrawable drawable = new GradientDrawable();
drawable.setColor(solidColor);
drawable.setStroke(strokeWidth, strokeColor);
drawable.setCornerRadius(radius);
return drawable;
}