android 自定义本地验证码demo,Android 自定义验证码输入框的实例代码(支持粘贴连续性)...

需求

1、能自定义输入框个数和样式

2、支持长按粘贴或剪切板内容自动填充(粘贴连续性)

其中第2点是最为重要的,正是其他人没有这点,逼得自己弄一个

示例

别人的示例:

ce5d0a4406d3849ee52e1ae966efdd47.gif

粘贴居然不支持连续性,只能粘贴第一个字符,所以用的有点难受

自己的示例:

9a738be4ddf05d9162ad1853c77eaefe.gif

原理

大致是edittext + n* textview,然后设置edittext字体跟背景颜色都为透明,隐藏光标

edittext:监听edittext每次输入一个字符就赋值到对应的textview上,然后在清空自己

下划线:在textview下面添加view

光标:这里的每个textview的焦点光标其实对view设置了valueanimator

粘贴:粘贴弹窗是自定义的popupwindow

源码有详细注释,这里就不一一说明

github

gradle

step 1. 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 {

implementation 'com.github.wshaobin:verificationcodeinputview:1.0.2'

}

how to use

in layout

android:id="@+id/vciv_code"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margintop="48dp"

android:gravity="center"

android:orientation="horizontal"

app:vciv_et_background="@android:color/white"

app:vciv_et_foucs_background="@android:color/holo_orange_dark"

app:vciv_et_cursor_color="@color/colorprimary"

app:vciv_et_height="58dp"

app:vciv_et_inputtype="number"

app:vciv_et_number="6"

app:vciv_et_text_color="@android:color/black"

app:vciv_et_text_size="18sp"

app:vciv_et_underline_default_color="@android:color/holo_green_dark"

app:vciv_et_underline_focus_color="@android:color/holo_blue_bright"

app:vciv_et_underline_height="2dp"

app:vciv_et_underline_show="true"

app:vciv_et_width="58dp" />

in java code

verificationcodeinputview view = findviewbyid(r.id.vciv_code);

view.setoninputlistener(new verificationcodeinputview.oninputlistener() {

@override

public void oncomplete(string code) {

toast.maketext(mainactivity.this, code, toast.length_short).show();

}

@override

public void oninput() {

}

});

//清除验证码

view.clearcode();

attributes

68ede702fb9bea5d85bc7188de60482d.png

vcinputtype

d2c8b30f14b0b5e91e80fc6d11ee5c02.png

输入框背景色支持类型

1、@drawable/xxx

2、@color/xxx

3、#xxxxxx

总结

以上所述是小编给大家介绍的android 自定义验证码输入框的实例代码(支持粘贴连续性),希望对大家有所帮助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值