前几天看了一篇关于本地验证码的实现的文章,自己跟着做了一下,也完成了博客的内容。但是我们既然学会了这个方法,就要开始投入使用。但是由于原文章没有写出如何实现输入验证码与验证码是否正确,所以我自己捣鼓了一下。首先申明,本人是菜鸟一个,所以虽然在各位大神看来很简单的问题但是我琢磨了一天才弄出来。
Demo拥有验证码的基本功能,点击切换图片,随机生成验证码,位置动态变化等,还预留了动态改变字体颜色等接口。下边贴出效果图:
输入我们看到的数字验证码1135,然后点击“验证”按钮,可以看到验证成功。
实现方法如下:
首先在XML文件中添加相应的控件,EditText、Button、自定义的View
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="@+id/edittext"
android:hint="请输入你看到的验证码0~9"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="验证" />
<com.zyb.checkview.CheckView
android:id="@+id/checkView"
android:layout_width="80sp"
android:layout_height="38sp"
android:layout_marginLeft="5dp" >
</com.zyb.checkview.CheckView>
</LinearLayout>