温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android中怎么通过自定义控件实现短信验证码自动填充

发布时间:2021-08-07 11:42:13 来源:亿速云 阅读:168 作者:Leah 栏目:编程语言

今天就跟大家聊聊有关Android中怎么通过自定义控件实现短信验证码自动填充,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

VerifyCodeView

VerifyCodeView是一个用于输入验证码的Android自定义控件,它支持数字类型的验证码,支持自定义外观,并且支持短信验证码自动填充。

项目地址:VerifyCodeView

在项目中引入VerifyCodeView

Gradle

dependencies { compile 'com.github.gongw:verifycodeview:1.0.2'}

Maven

<dependency> <groupId>com.github.gongw</groupId> <artifactId>verifycodeview</artifactId> <version>1.0.2</version> <type>pom</type></dependency>

支持的自定义属性

vcTextCount - 验证码长度  vcTextColor - 验证码字体颜色  vcTextSize - 验证码字体大小,单位sp  vcTextFont - 验证码字体样式文件路径(assets中的路径)  vcDividerWidth - 每个验证码之间的间隔距离,单位dp  vcWrapper - 包裹验证码的外观样式  vcWrapperStrokeWidth - 包裹验证码的外观的线条宽度,单位dp  vcWrapperColor - 包裹验证码的外观颜色  vcNextWrapperColor - 包裹将要被填充的验证码的外观颜色

使用示例

xml

<com.github.gongw.VerifyCodeView android:layout_width="240dp" android:layout_height="50dp" android:layout_marginTop="42dp" app:vcTextColor="#b63b21" app:vcTextCount="4" app:vcTextSize="36sp" app:vcDividerWidth="8dp" app:vcWrapper="centerLine" app:vcWrapperColor="#313335" app:vcNextWrapperColor="#b63b21" app:vcWrapperStrokeWidth="2dp" />

java

verifycodeView.setOnAllFilledListener(new VerifyCodeView.OnAllFilledListener() {  @Override  public void onAllFilled(String text) {   Toast.makeText(MainActivity.this, "filled by "+text, Toast.LENGTH_SHORT).show();  } });

自定义外观

verifycodeView.setVcWrapper(new VerifyCodeWrapper() {   @Override   public boolean isCovered() {    //whether the wrapper and verify code display together    return false;   }   @Override   public void drawWrapper(Canvas canvas, Paint paint, RectF rectF, RectF textRectF) { //draw your own wrapper   canvas.drawLine(textRectF.left - textRectF.width()/2, rectF.height()/2,   textRectF.right + textRectF.width() / 2, rectF.height()/2,   paint);   }  });

短信验证码自动填充

SmsVerifyCodeFilter filter = new SmsVerifyCodeFilter();filter.setSmsSenderStart("1096");filter.setSmsSenderContains("5225");filter.setSmsBodyStart("验证短信:");filter.setSmsBodyContains("验证码");filter.setVerifyCodeCount(verifyCodeView.getVcTextCount());verifyCodeView.startListen(filter);

看完上述内容,你们对Android中怎么通过自定义控件实现短信验证码自动填充有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI