我有一个向量图像,我想放在一个按钮上.不幸的是,我的图像显示为白色背景.如何用按钮的 colored颜色 填充背景?
这是按钮的代码.
@Composable
fun UserEducationPrimaryButton(
primaryButtonText: String,
primaryButtonClick: (() -> Unit)?,
showButtonArrow: Boolean
) {
val displayUtils = get<DisplayUtils>()
val configuration = LocalConfiguration.current
val screenWidth = displayUtils.convertDpToPixels(configuration.screenWidthDp * 1.0f)
val dpSize = DpSize(width = Dp(screenWidth.toFloat()), height = 52.dp)
// Use the state to change our UI
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val color = if (!isPressed) MaterialTheme.colors.secondary else Color.LightGray
val paddingValues = PaddingValues(horizontal = 32.dp, vertical = 10.dp)
//primary button
Button(
onClick = primaryButtonClick ?: {},
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp)
.size(dpSize),
shape = RoundedCornerShape(ROUNDED_CORNER_SHAPE_BUTTON),
interactionSource = interactionSource,
colors = ButtonDefaults.buttonColors(backgroundColor = color),
contentPadding = paddingValues
) {
Text(
modifier = Modifier,
textAlign = TextAlign.Center,
text = primaryButtonText,
style = TextStyle(
color = MaterialTheme.colors.onPrimary,
fontWeight = FontWeight.Bold,
fontSize = 17.sp
)
)
if (showButtonArrow) {
Spacer(modifier = Modifier.width(16.dp))
Surface (modifier = Modifier.fillMaxSize(),
color = color){
Image(
painter = rememberImagePainter(
ImageRequest.Builder(LocalContext.current)
.data(R.drawable.ic_user_education_arrow)
.build()
),
contentScale = ContentScale.Fit,
contentDescription = null,
modifier = Modifier,
colorFilter = ColorFilter.tint(
MaterialTheme.colors.onSecondary,
BlendMode.ColorBurn
),
)
}
}
}
}