前言
安卓的按压效果的传统方式是shape.xml文件,不过如果当项目比较多按钮都需要自定义按压效果的话,shape.xml的数量可是非常头疼的(即使是ctrl c+ ctrlv),故此可以采用动态方式进行按压效果的实现。
上代码
/**
*
* @param RADIUS
* 角度
* @param normalFileName
* 正常颜色
* @param pressFileName
* 点击颜色
* @param type
* -1:left 0:center 1:right 2:四角圆角
* @return
*/
public static StateListDrawable addDrawable(int RADIUS, int normalFileName,
int pressFileName, int type) {
StateListDrawable sd = new StateListDrawable();
if (RADIUS != 0) {
float[] float1 = null;
if (type == -1) {
float1 = new float[] { 0, 0, 0, 0, 0, 0, RADIUS, RADIUS };
} else if (type == 0) {
float1 = new float[] { 0, 0, 0, 0, 0, 0, 0, 0 };
} else if (type =