Advertisement

Responsive Advertisement

Gradient Button In jetpack compose custom button

Step 1 :-



@Composable
fun GradientButton(
text: String,
textColor: Color,
gradient: Brush,
onClick: () -> Unit
) {
Button(
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent
),
contentPadding = PaddingValues(),
onClick = { onClick() })
{
Box(
modifier = Modifier
.background(gradient)
.padding(horizontal = 50.dp, vertical = 30.dp),
contentAlignment = Alignment.Center
) {
Text(text = text, color = textColor, fontSize = 16.sp)
}
}
}

@Preview
@Composable
fun PreviewButton() {

GradientButton(
"Hii Roshan", Color.White, Brush.horizontalGradient(
colors = listOf(Color.Red, Color.Blue)
)
) {
Log.e("Roshan", "PreviewButton: Clicked")
}
}

Step 2:- 

Screenshot :-




Post a Comment

0 Comments