/**
* 设置颜色选择器
*
* @param defaultColorResId 默认状态的颜色资源id
* @param pressedColorResId 按下状态的颜色资源id
*/
public void addColorSelector(int defaultColorResId, int pressedColorResId) {
Drawable mDrawableDefault = getResources().getDrawable(defaultColorResId);
Drawable mDrawablePressed = getResources().getDrawable(pressedColorResId);
StateListDrawable drawable = new StateListDrawable();
//按下状态
drawable.addState(new int[]{android.R.attr.state_pressed}, mDrawablePressed);
//普通状态
drawable.addState(new int[]{-android.R.attr.state_focused, -android.R.attr.state_selected,
-android.R.attr.state_pressed}, mDrawableDefault);
this.setBackground(drawable);
}
/**
* 设置圆角
* @param roundRadius 圆角角度
*/
public void setCornerRadius(int roundRadius) {
GradientDrawable gd = new GradientDrawable();
gd.setCornerRadius(roundRadius);
gd.setColor(Color.parseColor(defalutColor));
this.setBackgroundDrawable(gd);
}
这两个方法单独使用,能够达到效果,为什么一起使用,就只有后面使用的那个方法的效果?
谢谢大神给指明道路啊!