实现一个实际信用卡用户界面的Android库:CreditCardView

jopen 9年前

CreditCardView是一个Android库,它允许开发人员创建能够复制一个实际的信用卡用户界面。

Displaying and entering the credit card details inside the app has become a very common use case seen in a lot of different apps, but it is often represented in a not so intuitive manner. With Android Pay being announced at the recent Google I/O 2015, more apps would require users to input their credit card details. I created this library with the aim of making the process of displaying and entering the credit card details more visually appealing to the users of your app.

Screenshots

Screenshots

Features

  • Pre-built card backgrounds to help you get started quickly
  • Fully Customizable
  • Auto selection of drawables based on the credit card number pattern i.e. Visa, Mastercard,American Express & Discover. Will be adding more soon based on the requests I get
  • Auto selection of logo drawable based on the credit card type i.e. Visa, Mastercard and American Express
  • Editable and non-editable mode
  • 4 different card number formats

Setup

The library is pushed to Maven Central as an AAR, so you just need to add the following to your build.gradle file:

dependencies {      compile ‘com.vinaygaba:creditcardview:1.0.2’  }

Usage

Using CreditCardView is extremely easy, this is how you would declare it in the layout xml:

<!-- Use <com.example.vinay.library.CreditCardView/> if you are using v1.0.1 of the library-->    <com.vinaygaba.creditcardview.CreditCardView          android:id="@+id/card1"          android:layout_width="fill_parent"          android:layout_height="225dp"          android:background="@drawable/cardbackground_world"          android:layout_marginBottom="16dp"          android:layout_marginTop="16dp"          app:cardNumber="5500005555555559"          app:cardName="Vinay Gaba"          app:cardNumberTextColor="#cccccc"          app:cardNumberFormat="masked_all_but_last_four"          app:cardNameTextColor="#cccccc"          app:type="auto"          app:brandLogo="@drawable/brandlogo"          app:putChip="true"          app:expiryDate = "02/22"          app:expiryDateTextColor="#cccccc"          app:isEditable="true"          app:validTillTextColor="#cccccc"          app:hintTextColor = "#cccccc"          />

Remember to put this for custom attribute usage:

xmlns:app="http://schemas.android.com/apk/res-auto" 

And this is how you would be adding it programatically in java:

CreditCardView creditCardView= new CreditCardView(this);

OR

CreditCardView creditCardView= (CreditCardView)findViewById(R.id.ID_OF_CARD);

项目主页:http://www.open-open.com/lib/view/home/1435498588903