Skip to Content
Docs

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

ParameterTypeRequiredDescription
textStyleTextStyleNoThe 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).
textColorColorNoThe text. Default: Color(0xFF16201D).
placeholderColorColorNoThe placeholder, and an outlined field's label while it isn't focused. Default: Color(0xFF8A9590).
invalidColorColorNoThe text, cursor, and border of an invalid field, and an outlined field's label and errorText in its error state. Default: Color(0xFFB3261E).
backgroundColorColorNoThe field's background. Default: Color(0xFFF5F6F4).
borderColorColorNoThe border while the field isn't focused. Default: Color(0xFFD9DFDB).
focusedBorderColorColorNoThe border and cursor while the field is focused, and an outlined field's floating label. Default: Color(0xFF0D6B57).
borderWidthDpNoThe border's width. An outlined field's border is 1 dp wider while it's focused. Default: 1.dp.
shapeShapeNoThe field's corners. Default: RoundedCornerShape(8.dp).
contentPaddingPaddingValuesNoThe 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

Was this page helpful?