Skip to content
A ready-made card form layout that can be included in your Android app, making it easy to accept credit and debit cards.
Java Ruby Shell
Branch: master
Clone or download

Card Form

Build Status

Card Form is a ready made card form layout that can be included in your app making it easy to accept credit and debit cards.

Adding It To Your Project

Add the dependency in your build.gradle:

dependencies {
    implementation 'com.braintreepayments:card-form:4.2.0'

To use the latest build from the master branch use:

dependencies {
   implementation 'com.braintreepayments:card-form:4.2.1-SNAPSHOT'


Card Form is a LinearLayout that you can add to your layout:

    android:layout_height="match_parent" />

To initialize the view and change which fields are required for the user to enter, use the required field methods and CardForm#setup(AppCompatActivity activity).

CardForm cardForm = (CardForm) findViewById(;
        .mobileNumberExplanation("SMS is required on this number")

To access the values in the form, there are getters for each field:


To check if CardForm is valid call CardForm#isValid(). To validate each required field and show the user which fields are incorrect, call CardForm#validate().

To set custom error messages on a field call CardForm#setCardNumberError(String) on the given field.

Additionally CardForm has 4 available listeners:

  • CardForm#setOnCardFormValidListener called when the form changes state from valid to invalid or invalid to valid.
  • CardForm#setOnCardFormSubmitListener called when the form should be submitted.
  • CardForm#setOnFormFieldFocusedListener called when a field in the form is focused.
  • CardForm#setOnCardTypeChangedListener called when the CardType in the form changes.

The card form is compatible with

To use, add the dependency in your build.gradle:

dependencies {
    api 'io.card:android-sdk:[5.5.0,6.0.0)'

Check if is available for use:


Scan a card:




The card form uses the Android Design Support Library for styling and floating labels. All card form inputs use the colorAccent theme attribute, when present, to set their focused color. For more information on the colorAccent attribute, see Using the Material Theme. Additional styling, such as the error color (textErrorColor) can be set in your theme and will be picked up by the card form.

The included sample app has examples with a light theme and dark theme.

Note: Any Activity using the card form must use a style that is a Theme.AppCompat theme or descendant (defines This is a requirement of the Android Design Support Library. If this is a problem in your usage of the card form, please file an issue and we will look further into workarounds for this.



Card Form is open source and available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.