要使用int颜色设置MaterialShapeDrawable的背景颜色,可以按照以下步骤进行:
MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable();
int color = getResources().getColor(R.color.your_color); // 替换为你的颜色资源
ColorStateList colorStateList = ColorStateList.valueOf(color);
shapeDrawable.setFillColor(colorStateList);
View view = findViewById(R.id.your_view); // 替换为你的View
view.setBackground(shapeDrawable);
这样就可以使用int颜色设置MaterialShapeDrawable的背景颜色了。
完整示例代码如下:
MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable();
int color = getResources().getColor(R.color.your_color); // 替换为你的颜色资源
ColorStateList colorStateList = ColorStateList.valueOf(color);
shapeDrawable.setFillColor(colorStateList);
View view = findViewById(R.id.your_view); // 替换为你的View
view.setBackground(shapeDrawable);
请确保将R.color.your_color
替换为你的颜色资源的引用。