Skip to main content

Android Element Types

TextElement

The TextElement can be used to collect any text data within your mobile application. This component allows you to fully customize the look and feel to match your brand, and it does not allow direct access the underlying plaintext values entered by a user, keeping your mobile application out of compliance scope.

Basic Usage

To use the TextElement within your Android application, simply include the view within one of your Android application’s layouts.

<com.basistheory.android.view.TextElement
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Properties can be programmatically initialized within your views within either the onCreate or onCreateView lifecycle methods.

Configuration

The TextElement extends the native FrameLayout view, so all standard properties and attributes supported by FrameLayout are supported by TextElement.

Properties

The following additional properties are supported when programmatically interacting with a TextElement:

NameTypeDescription
hintStringPlaceholder text to display within the element when empty.
isCompleteBooleanWhether this element satisfies the mask and validator, i.e. it is ready to be tokenized.
isEditableBooleanWhether this element is editable or readonly.
isEmptyBooleanWhether this element is empty.
isMaskSatisfiedBooleanWhether this element satisfies the length and format requirements of the mask, if defined. Defaults to true if this element does not have a mask.
isValidBooleanThe result of this element's validator, if defined. Defaults to true if this element does not have a validator.
keyboardTypeKeyboardTypeThe type of keyboard to display when editing. Supported values are KeyboardType.TEXT and KeyboardType.NUMBER.
maskElementMaskRestricts and formats input entered into this Element. See the Mask options for details.
removeDefaultStylesBooleanRemoves the default Android styling on the underlying EditText. Defaults to true.
textColorIntA color value in the form 0xAARRGGBB. Do not pass a resource ID. To get a color value from a resource ID, call getColor.
textSizeFloatThe font size, in pixels.
transformElementTransformTransforms the value of this Element prior to tokenization. See the Transform options for details.
validatorElementValidatorValidates the value of this Element. See the Validator options for details.

Methods

SignatureDescription
addBlurEventListener(listener: (BlurEvent) -> Unit)Adds a listener for any BlurEvents raised by this element.
addChangeEventListener(listener: (ChangeEvent) -> Unit)Adds a listener for any ChangeEvents raised by this element.
addFocusEventListener(listener: (FocusEvent) -> Unit)Adds a listener for any FocusEvents raised by this element.
setText(value: String?)Sets the text value for the element. Note that a getter is not exposed on the TextElement to retrieve the underlying text value.
setValueRef(elementValueReference: ElementValueReference)Sets the element's text to the value referenced by the provided ElementValueReference.
setValueRef(element: TextElement)Binds the provided element: TextElement instance as a value source for this element, keeping the value of this element in sync with any changes made to the other element.
ElementValueReference is a class that stores a reference to a value which can only be accessed by BasisTheoryElements, so that you can reference data without touching the plaintext value and pulling your application into compliance scope.
When using setValueRef to keep a TextElement in sync with another element, or to set the text of an element, it is strongly recommended that you make the element that is being acted upon readonly. This is possible by setting isEditable=false.

XML Attributes

The following additional XML attributes are also supported when defining a TextElement in a layout XML file:

NameTypeDescription
editablebooleanWhether this element is editable or readonly.
hintStringPlaceholder text to display within the Element.
keyboardTypeenumThe type of keyboard to display when editing. Supported values are text and number.
maskstringA string defining the mask applied to this Element, e.g. (###-##-####).
removeDefaultStylesbooleanRemoves the default Android styling on the underlying EditText. Defaults to true.
textstringSets the text value for the element. Note that a getter is not exposed on the TextElement to retrieve the underlying text value.
textColorreference|colorThe text color.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb"
textSizedimensionThe size of text.

CardNumberElement

The CardNumberElement can be used to securely collect credit card numbers within your application. This element will render a text input within your view to accept a card number entered by your end users.

This element was designed to be used in conjunction with the CardExpirationDateElement and CardVerificationCodeElement to collect and tokenize a card token.

Basic Usage

To use the CardNumberElement within your Android application, simply include the view within one of your Android application’s layouts.

<com.basistheory.android.view.CardNumberElement
android:id="@+id/card_number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

This element can be referenced directly when tokenizing through the BasisTheoryElements service class:

val cardNumberElement = findViewById<CardNumberElement>(R.id.card_number)
...

val tokenizeResponse = bt.tokenize(object {
val type = "card"
val data = object {
val number = cardNumberElement
val expiration_month = cardExpirationDateElement.month()
val expiration_year = cardExpirationDateElement.year()
val cvc = cardVerificationCodeElement
}
})

The element serves as a reference that can only be resolved back to the original value by the BasisTheoryElements service when tokenizing. Your application is not given direct access to the underlying plaintext value.

Configuration

The CardNumberElement extends the TextElement view, so all properties and attributes supported by TextElement are also supported here.

By default, this element is configured with:

  • The keyboard is configured to only allow numeric input
  • A mask is applied to format input values according to the card brand
  • The LuhnValidator is applied to restrict input to Luhn-valid cards

This component fully supports the same style customizations to match your branding that are supported on the base TextElement.

Card Brands

The first several digits of the card number are analyzed as the user is typing to determine the card brand. The brand is used to automatically set a mask to a brand-specific format. If the CardNumberElement is bound to a CardVerificationCodeElement, a mask is also automatically set on the CardVerificationCodeElement based on the brand's CVC length requirements.

Supported card brands are defined in the table below:

BrandIdentifierCard Number DigitsCVC Digits
American Expressamerican-express154
Diners Clubdiners-club14, 16, 193
Discoverdiscover16, 193
Eloelo163
Hiperhiper163
HiperCardhipercard163
JCBjcb16-193
Maestromaestro12-193
Mastercardmastercard163
MIRmir16-193
UnionPayunionpay14-193
Visavisa16, 18, 193
Some card brands have issued card numbers with multiple lengths. The Card Number Digits column documents all acceptable card number lengths for the brand (in number of digits, excluding formatting characters).

CardMetadata

The brand details and other card metadata are made available to your application within the cardMetadata property on the CardNumberElement:

NameTypeDescription
cardMetadataCardMetadataGets metadata about the card, derived from user input.

The CardMetadata object contains the properties:

NameTypeDescription
brandStringThe card brand identifier
binStringThe first 6 digits of the card number if complete, otherwise null
last4StringThe last 4 digits of the card number if complete, otherwise null

ChangeEvent Details

The CardNumberElement emits ChangeEvents that may contain several types of EventDetail records.

  • cardBrand: Contains the card brand identifier. Only included once enough digits are entered to determine a card brand.
  • cardBin: Contains the first 6 digits of the card number. Only included for complete card numbers satisfying the brand-specific mask.
  • cardLast4: Contains the last 4 digits of the card number. Only included for complete card numbers satisfying the brand-specific mask.

CardExpirationDateElement

The CardExpirationDateElement can be used to securely collect credit card expiration dates within your application. This element will render a text input within your view that accepts input in the form MM/yy.

This element was designed to be used in conjunction with the CardNumberElement and CardVerificationCodeElement to collect and tokenize a card token.

Basic Usage

To use the CardExpirationDateElement within your Android application, simply include the view within one of your Android application’s layouts.

<com.basistheory.android.view.CardExpirationDateElement
android:id="@+id/expiration_date"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

The month and year values can be referenced separately when tokenizing through the BasisTheoryElements service class:

val tokenizeResponse = bt.tokenize(object {
val type = "card"
val data = object {
val number = cardNumberElement
val expiration_month = cardExpirationDateElement.month()
val expiration_year = cardExpirationDateElement.year()
val cvc = cardVerificationCodeElement
}
})

The month() and year() functions expose a reference object that can only be resolved back to the original values by the BasisTheoryElements service when tokenizing. These methods do not provide your application with direct access to the underlying plaintext values.

Configuration

The CardExpirationDateElement extends the TextElement view, so all properties and attributes supported by TextElement are also supported here.

By default, this element is configured with:

  • The keyboard is configured to only allow numeric input
  • A mask is applied to format input values as MM/yy
  • The FutureDateValidator is applied to restrict input to future dates

This component fully supports the same style customizations to match your branding that are supported on the base TextElement.

Additional Methods Supported

SignatureDescription
month(): ElementValueReferenceReturns a value reference you can use when tokenizing without touching the raw value.
year(): ElementValueReferenceReturns a value reference you can use when tokenizing without touching the raw value.
setValueRef(monthRef: ElementValueReference, yearRef: ElementValueReference)Sets the expiration date to the value referenced by the provided references.

CardVerificationCodeElement

The CardVerificationCodeElement can be used to securely collect credit card CVC values within your application. This element will render a text input within your view that accepts either a 3 or 4 digit CVC (the length is determined by the card brand).

This element was designed to be used in conjunction with the CardNumberElement and CardExpirationDateElement to collect and tokenize a card token.

Basic Usage

To use the CardVerificationCodeElement within your Android application, simply include the view within one of your Android application’s layouts.

<com.basistheory.android.view.CardVerificationCodeElement
android:id="@+id/cvc"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

You can optionally bind a CardNumberElement to your CardVerificationCodeElement to automatically enforce the CVC length validation corresponding to the entered card brand.

val cardNumberElement = findViewById<CardNumberElement>(R.id.card_number)
val cvcElement = findViewById<CardVerificationCodeElement>(R.id.cvc)
cvcElement.cardNumberElement = cardNumberElement // optional binding between these two elements

This element can be referenced directly when tokenizing through the BasisTheoryElements service class:

val tokenizeResponse = bt.tokenize(object {
val type = "card"
val data = object {
val number = cardNumberElement
val expiration_month = cardExpirationDateElement.month()
val expiration_year = cardExpirationDateElement.year()
val cvc = cardVerificationCodeElement
}
})

The element serves as a reference that can only be resolved back to the original value by the BasisTheoryElements service when tokenizing. Your application is not given direct access to the underlying plaintext value.

Configuration

The CardVerificationCodeElement extends the TextElement view, so all properties and attributes supported by TextElement are also supported here.

By default, this element is configured with:

  • The keyboard is configured to only allow numeric input
  • A 3 digit mask is applied by default, but this may be automatically changed to a 4 digit mask based on the card brand

This component fully supports the same style customizations to match your branding that are supported on the base TextElement.