Style the card fields
Set the card fields' text, colors, border, corners, and padding to match your app.
PayFieldStyle configures the text, colors, border, corners, and padding of the card fields. Pass it to each field as style, or set it as each View version's style. The labels, the error text, and the layout around the fields belong to your app, or to a Compose field's label and errorText.
The drop-in takes a PayFieldStyle for its card fields too.
val style = PayFieldStyle(shape = RoundedCornerShape(12.dp), focusedBorderColor = Color(0xFF3F51B5))
PayCardNumberField(card, style = style)Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
textStyle | TextStyle | No | The typography (font, size, and weight) for the input text and placeholder. Its color is replaced by textColor, placeholderColor, or invalidColor. Default: TextStyle(fontSize = 16.sp). |
textColor | Color | No | The text. Default: Color(0xFF16201D). |
placeholderColor | Color | No | The placeholder, and an outlined field's label while it isn't focused. Default: Color(0xFF8A9590). |
invalidColor | Color | No | The text, cursor, and border of an invalid field, and an outlined field's label and errorText in its error state. Default: Color(0xFFB3261E). |
backgroundColor | Color | No | The field's background. Default: Color(0xFFF5F6F4). |
borderColor | Color | No | The border while the field isn't focused. Default: Color(0xFFD9DFDB). |
focusedBorderColor | Color | No | The border and cursor while the field is focused, and an outlined field's floating label. Default: Color(0xFF0D6B57). |
borderWidth | Dp | No | The border's width. An outlined field's border is 1 dp wider while it's focused. Default: 1.dp. |
shape | Shape | No | The field's corners. Default: RoundedCornerShape(8.dp). |
contentPadding | PaddingValues | No | The space around the text in a boxed field. An outlined field, with a label, uses Material 3's padding. Default: PaddingValues(horizontal = 12.dp, vertical = 14.dp). |
Example
Take the style from your Compose theme:
@Composable
fun themedFieldStyle(): PayFieldStyle {
val colors = MaterialTheme.colorScheme
return PayFieldStyle(
textStyle = MaterialTheme.typography.bodyLarge,
textColor = colors.onSurface,
placeholderColor = colors.onSurfaceVariant,
invalidColor = colors.error,
backgroundColor = colors.surface,
borderColor = colors.outline,
focusedBorderColor = colors.primary,
shape = MaterialTheme.shapes.small,
)
}
val style = themedFieldStyle()
PayCardNumberField(card, style = style, label = "Card number")With the View versions, set it on each view:
val style = PayFieldStyle(
textColor = Color(0xFF1B1B1F),
backgroundColor = Color.White,
focusedBorderColor = Color(0xFF3F51B5),
shape = RoundedCornerShape(12.dp),
)
listOf(binding.cardNumber, binding.cardExpiry, binding.cardCvc).forEach { it.style = style }Next steps
- Card fields: The fields, their labels, and their View versions.
- Style the drop-in: The drop-in's colors, fonts, and card fields.
Was this page helpful?