Skip to main content

Advanced Configurations

Customize the Overlay Appearance

To customize the appearance of the overlay, you can implement a LabelCaptureBasicOverlayListener.

The method brushForLabel() is called every time a label is captured, and brushForField() is called for each of its fields to determine the brush for the label or field.

overlay.listener = object : LabelCaptureBasicOverlayListener {
/*
* Customize the appearance of the overlay for the individual fields.
*/
override fun brushForField(
overlay: LabelCaptureBasicOverlay,
field: LabelField,
label: CapturedLabel
): Brush? = when (field.name) {
"<your-barcode-field-name>" -> Brush(Color.CYAN.withAlpha(128), Color.CYAN, 1f)
"<your-expiry-date-field-name>" -> Brush(Color.GREEN.withAlpha(128), Color.GREEN, 1f)
else -> Brush(Color.TRANSPARENT, Color.TRANSPARENT, 0f)
}

/*
* Customize the appearance of the overlay for the full label.
* In this example, we disable label overlays by returning null always.
*/
override fun brushForLabel(
overlay: LabelCaptureBasicOverlay,
label: CapturedLabel
): Brush? = null

override fun onLabelTapped(
overlay: LabelCaptureBasicOverlay,
label: CapturedLabel
) {
/*
* Handle the user tap gesture on the label.
*/
}
}

tip

You can also use LabelCaptureBasicOverlay.setLabelBrush() and LabelCaptureBasicOverlay.setCapturedFieldBrush() to configure the overlay if you don't need to customize the appearance based on the name or content of the fields.