待集成Android开发自定义view

仿微信、支付宝等简洁的验证码、密码输入框

2017-03-06  本文已影响835人  大利猫

VerificationCodeInput

验证码输入控件

How to use

<com.dalimao.corelibrary.VerificationCodeInput
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ver:box="4"
        ver:child_h_padding="5dp"
        android:layout_centerInParent="true"
        android:id="@+id/verificationCodeInput"
        android:layout_marginBottom="16dp"
        />

监听输入完成:

VerificationCodeInput input = (VerificationCodeInput) findViewById(R.id.verificationCodeInput);
input.setOnCompleteListener(new VerificationCodeInput.Listener() {
      @Override
      public void onComplete(String content) {
         Log.d(TAG, "完成输入:" + content);
      }
});

你还可以为输入框定义自己的样式,指定属性 box_bg_normal 和 box_bg_focus:

<com.dalimao.corelibrary.VerificationCodeInput
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ver:box="4"
        ver:box_bg_normal="@drawable/verification_edit_bg_normal"
        ver:box_bg_focus="@drawable/verification_edit_bg_focus"
        ver:child_h_padding="5dp"
        android:layout_centerInParent="true"
        android:layout_marginBottom="16dp"
        />

自定义个数,指定属性 box:

<com.dalimao.corelibrary.VerificationCodeInput
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ver:box="5"
        ver:box_bg_normal="@drawable/verification_edit_bg_normal"
        ver:box_bg_focus="@drawable/verification_edit_bg_focus"
        ver:child_h_padding="5dp"
        android:layout_centerInParent="true"
        android:layout_marginBottom="16dp"
        />
样式定义

Gradle dependencies

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
        compile 'com.github.liuguangli:VerificationCodeInput:1.2'
}

源码

点这儿

上一篇 下一篇

猜你喜欢

热点阅读