百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

android-card-form

> 编程语言
开源

一个预先设计好的卡片表单布局,可添加到 Android 应用中,从而方便地接受信用卡和借记卡。

373 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个预先设计好的卡片表单布局,可添加到 Android 应用中,从而方便地接受信用卡和借记卡。

Card Form

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:

groovy
dependencies {
    implementation 'com.braintreepayments:card-form:5.4.0'
}

Usage

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

xml

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).

java
CardForm cardForm = (CardForm) findViewById(R.id.card_form);
cardForm.cardRequired(true)
        .expirationRequired(true)
        .cvvRequired(true)
        .cardholderName(CardForm.FIELD_REQUIRED)
        .postalCodeRequired(true)
        .mobileNumberRequired(true)
        .mobileNumberExplanation("SMS is required on this number")
        .actionLabel("Purchase")
        .setup(activity);

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

java
cardForm.getCardNumber();
cardForm.getExpirationMonth();
cardForm.getExpirationYear();
cardForm.getCvv();
cardForm.getCardholderName();
cardForm.getPostalCode();
cardForm.getCountryCode();
cardForm.getMobileNumber();

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.

Example

Styling

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 android.support.v7.appcompat.R.attr.colorPrimary). 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.

Releases

License

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaandroidcredit-carddebit-cardpayments

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言