Skip to content

Repository files navigation

更多我的CSDN博客

联系: QQ 839539179 WEIXIN tuojie003

VerificationCodeView —正方形验证码输入框


示例:

动图演示

apk演示:点击下载


特性

自定义属性

name说明format默认值
icv_et_number输入框的数量integer1
icv_et_width输入框的宽度dimension42dp
icv_et_divider_drawable输入框之间的间隔reference默认图片
icv_et_text_color输入框文字颜色colorColor.WHITE
icv_et_text_size输入框文字大小dimension16sp
icv_et_bg_focus输入框获取焦点时边框reference默认边框
icv_et_bg_normal输入框没有焦点时边框reference默认边框

可使用方法

method_namedescriptionreturn_type
getInputContent获取输入内容String
clearInputContent清空输入内容Void
setEtNumber(int etNumber)设置输入框个数Void
getEtNumber获取输入框个数int
setInputCompleteListener(InputCompleteListener istener)设置输入和删除时的监听Void

原理说明

该项目是一个继承于RelativeLayout的组合控价型的自定义View,在布局中文件中使用了一个透明的EditView来接受用户的输入事件, 在布局文件的LinearLayout中动态添加正方形输入框,正方形输入框其实是一个个的TextView。


使用方法

1 Gradle引用

implementation 'com.jacktuotuo.customview:verificationcodeview:1.0.2'

2 xml中使用

  • 简单配置
<com.tuo.customview.VerificationCodeView
android:id="@+id/icv_1"app:icv_et_number="5"android:layout_width="wrap_content"android:layout_height="wrap_content" />
  • 个性化配置
<com.tuo.customview.VerificationCodeView
android:id="@+id/icv"android:layout_width="match_parent"android:layout_height="50dp"android:layout_centerHorizontal="true"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_marginTop="26dp"app:icv_et_bg_focus="@drawable/shape_icv_et_bg_focus"app:icv_et_bg_normal="@drawable/shape_icv_et_bg_normal"app:icv_et_divider_drawable="@drawable/shape_divider_identifying"app:icv_et_number="6"app:icv_et_text_color="#000000"app:icv_et_width="50dp" />

3 java代码中使用

VerificationCodeView codeView = new VerificationCodeView(context);
codeView.setEtNumber(number);

Update Log

version 1.0.1

  • 支持Java代码中动态设置输入框个数
  • 支持xml中只配置宽高,输入框个数默认为1

version 1.0.2

  • 修复设置字体大小的bug

TODO

version-1.0.1

  • 支持在Java中动态设置输入框个数

version-1.0.2

  • 支持密码模式

License

Copyright 2017 JackTuoTuo

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressor implied.See the License for the specific language governing permissions and limitations under the License.

About

正方形验证码输入框

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages