首先,我将绿色设置为View mIcon的背景,
View mIcon = findViewById(R.id.xxx);
GradientDrawable gdraw = (GradientDrawable) mContext.getResources().getDrawable(R.drawable.roundbtn_white_normal);
gdraw.setColor(Color.GREEN);
mIcon.setBackgroundDrawable(gdraw);
然后,我不知道如何从该视图的背景中获取颜色......没有 getColor()
功能...
到目前为止,下面的课程对我来说效果很好。
import android.content.res.Resources;
...
// it's the same with the GradientDrawable, just make some proper modification to make it compilable
public class ColorGradientDrawable extends Drawable {
...
private int mColor; // this is the color which you try to get
...
// original setColor function with little modification
public void setColor(int argb) {
mColor = argb;
mGradientState.setSolidColor(argb);
mFillPaint.setColor(argb);
invalidateSelf();
}
// that's how I get the color from this drawable class
public int getColor() {
return mColor;
}
...
// it's the same with GradientState, just make some proper modification to make it compilable
final public static class GradientState extends ConstantState {
...
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)