Android xml背景代码改色

94 阅读1分钟

if (labelView.getBackground() instanceof GradientDrawable) {
    GradientDrawable drawable = (GradientDrawable) labelView.getBackground();
    drawable.mutate();
    // 改背景色
    drawable.setColor(Color.parseColor(backgroundColor));
    // 改背景边框色
//drawable.setStroke(DeviceUtil.dp2px(0.5f),Color.parseColor(backgroundColor));

}