@Override
public void setBackgroundColor(int color) {
backgroundColor = color;
if (isEnabled()) {
beforeBackground = backgroundColor;
}
try {
LayerDrawable layer = (LayerDrawable) getBackground();
// 每个按钮的框架都是由drawable中的xml文件制定的,xml文件中都有一个item的id叫:shape_bacground
GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
/**
* 给这个图片设置背景色,因为图片的主体是透明的所以可以直接显示背景色
* 效果就是一个透明但有阴影的框架下有了背景色,这样的方式可以方便的设置不同颜色的按钮,让按钮看起来还是浑然一体
*/
shape.setColor(backgroundColor);
/**
* 当重新设定背景色后,要检查涟漪颜色。如果已经设定了涟漪颜色,那么就用之前的。如果没设定就重新生成
*/
if (!settedRippleColor) {
rippleColor = makePressColor(255);
}
} catch (Exception ex) {
// Without bacground
}
}
Button.java 文件源码
java
阅读 36
收藏 0
点赞 0
评论 0
项目:XERUNG
作者:
评论列表
文章目录