update reademe

This commit is contained in:
吃苹果的猫
2017-11-02 18:22:41 +08:00
parent 47e693b96d
commit 366b4b33f8
2 changed files with 19 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
Android 自定义方形输入框,仿滴滴验证码、小篮单车验证码输入框
##效果图
![Screenshot](screenshot/screenshot.gif)
GIF被压缩的有点模糊下面是截图
@@ -109,7 +110,17 @@ Step 2. Add the dependency
```
dependencies {
compile 'com.jyn.verificationcodeview:verificationcodeview:1.0.0'
compile 'com.jyn.verificationcodeview:verificationcodeview:1.0.0'
}
```
```
## 开发思路
简书:[http://www.jianshu.com/p/781950fe5e73](http://www.jianshu.com/p/781950fe5e73)
CSDN[http://blog.csdn.net/jiaoyaning1210/article/details/78427818](http://blog.csdn.net/jiaoyaning1210/article/details/78427818)
---
如果对您有帮助的话还请给个收藏或者star谢谢
---

View File

@@ -158,7 +158,7 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
EditText editText = new EditText(mContext);
initEditText(editText, i);
addView(editText);
if (i == 0) {
if (i == 0) { //设置第一个editText获取焦点
editText.setFocusable(true);
}
}
@@ -256,6 +256,7 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
private void focus() {
int count = getChildCount();
EditText editText;
//利用for循环找出还最前面那个还没被输入字符的EditText并把焦点移交给它。
for (int i = 0; i < count; i++) {
editText = (EditText) getChildAt(i);
if (editText.getText().length() < 1) {
@@ -266,16 +267,18 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
editText.setCursorVisible(false);
}
}
//如果最后一个输入框有字符,则返回结果
EditText lastEditText = (EditText) getChildAt(mEtNumber - 1);
if (lastEditText.getText().length() > 0) {
lastEditText.requestFocus();
getResult();
}
}
private void backFocus() {
//博主手机不好,经常点一次却触发两次`onKey`事件就设置了一个防止多点击间隔100毫秒。
long startTime = System.currentTimeMillis();
EditText editText;
//循环检测有字符的`editText`,把其置空,并获取焦点。
for (int i = mEtNumber - 1; i >= 0; i--) {
editText = (EditText) getChildAt(i);
if (editText.getText().length() >= 1 && startTime - endTime > 100) {