fix bug 解决输入完成后,再点击输入框焦点转移问题
This commit is contained in:
@@ -191,22 +191,18 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
EditText editText = new EditText(mContext);
|
EditText editText = new EditText(mContext);
|
||||||
initEditText(editText, i);
|
initEditText(editText, i);
|
||||||
addView(editText);
|
addView(editText);
|
||||||
if (i == 0) { //设置第一个editText获取焦点
|
//设置第一个editText获取焦点
|
||||||
|
if (i == 0) {
|
||||||
editText.setFocusable(true);
|
editText.setFocusable(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initEditText(EditText editText, int i) {
|
private void initEditText(EditText editText, int i) {
|
||||||
|
|
||||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(mEtWidth, mEtWidth);
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(mEtWidth, mEtWidth);
|
||||||
// layoutParams.bottomMargin = childVPadding;
|
|
||||||
// layoutParams.topMargin = childVPadding;
|
|
||||||
layoutParams.leftMargin = mEtSpacing;
|
layoutParams.leftMargin = mEtSpacing;
|
||||||
layoutParams.rightMargin = mEtSpacing;
|
layoutParams.rightMargin = mEtSpacing;
|
||||||
|
|
||||||
layoutParams.gravity = Gravity.CENTER;
|
layoutParams.gravity = Gravity.CENTER;
|
||||||
|
|
||||||
editText.setLayoutParams(layoutParams);
|
editText.setLayoutParams(layoutParams);
|
||||||
editText.setGravity(Gravity.CENTER);
|
editText.setGravity(Gravity.CENTER);
|
||||||
editText.setId(i);
|
editText.setId(i);
|
||||||
@@ -253,6 +249,13 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
int measuredWidth = getMeasuredWidth();
|
||||||
|
Log.i("main", "measuredWidth:" + measuredWidth);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
|
||||||
@@ -306,8 +309,12 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
editText.setCursorVisible(false);
|
editText.setCursorVisible(false);
|
||||||
|
if (i == count - 1) {
|
||||||
|
editText.requestFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果最后一个输入框有字符,则返回结果
|
//如果最后一个输入框有字符,则返回结果
|
||||||
EditText lastEditText = (EditText) getChildAt(mEtNumber - 1);
|
EditText lastEditText = (EditText) getChildAt(mEtNumber - 1);
|
||||||
if (lastEditText.getText().length() > 0) {
|
if (lastEditText.getText().length() > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user