update
This commit is contained in:
@@ -16,7 +16,22 @@
|
|||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
app:vcv_et_bg="@drawable/et_login_code"
|
app:vcv_et_bg="@drawable/et_login_code"
|
||||||
app:vcv_et_cursor="@drawable/et_cursor"
|
app:vcv_et_cursor="@drawable/et_cursor"
|
||||||
app:vcv_et_inputType="number"
|
app:vcv_et_inputType="numberPassword"
|
||||||
|
app:vcv_et_number="4"
|
||||||
|
app:vcv_et_text_color="@android:color/black"
|
||||||
|
app:vcv_et_text_size="6sp" />
|
||||||
|
|
||||||
|
<com.jyn.vcview.VerificationCodeView
|
||||||
|
android:id="@+id/verificationcodeview2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="30dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
app:vcv_et_bg="@drawable/et_login_code"
|
||||||
|
app:vcv_et_cursor="@drawable/et_cursor"
|
||||||
|
app:vcv_et_cursor_visible="false"
|
||||||
|
app:vcv_et_inputType="numberPassword"
|
||||||
app:vcv_et_number="4"
|
app:vcv_et_number="4"
|
||||||
app:vcv_et_text_color="@android:color/black"
|
app:vcv_et_text_color="@android:color/black"
|
||||||
app:vcv_et_text_size="6sp" />
|
app:vcv_et_text_size="6sp" />
|
||||||
@@ -34,7 +49,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:onClick="clear"
|
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
|
android:onClick="clear"
|
||||||
android:text="清空输入框" />
|
android:text="清空输入框" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import android.text.InputFilter;
|
|||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -60,6 +61,8 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
*/
|
*/
|
||||||
private int mEtTextBg;
|
private int mEtTextBg;
|
||||||
|
|
||||||
|
private boolean cursorVisible;
|
||||||
|
|
||||||
private int mCursorDrawable;
|
private int mCursorDrawable;
|
||||||
|
|
||||||
public OnCodeFinishListener getOnCodeFinishListener() {
|
public OnCodeFinishListener getOnCodeFinishListener() {
|
||||||
@@ -127,9 +130,22 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum VCInputType {
|
public enum VCInputType {
|
||||||
|
/**
|
||||||
|
* 数字类型
|
||||||
|
*/
|
||||||
NUMBER,
|
NUMBER,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字密码
|
||||||
|
*/
|
||||||
NUMBERPASSWORD,
|
NUMBERPASSWORD,
|
||||||
|
/**
|
||||||
|
* 文字
|
||||||
|
*/
|
||||||
TEXT,
|
TEXT,
|
||||||
|
/**
|
||||||
|
* 文字密码
|
||||||
|
*/
|
||||||
TEXTPASSWORD,
|
TEXTPASSWORD,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,12 +157,13 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
mEtNumber = typedArray.getInteger(R.styleable.vericationCodeView_vcv_et_number, 4);
|
mEtNumber = typedArray.getInteger(R.styleable.vericationCodeView_vcv_et_number, 4);
|
||||||
int inputType = typedArray.getInt(R.styleable.vericationCodeView_vcv_et_inputType, VCInputType.NUMBER.ordinal());
|
int inputType = typedArray.getInt(R.styleable.vericationCodeView_vcv_et_inputType, VCInputType.NUMBER.ordinal());
|
||||||
mEtInputType = VCInputType.values()[inputType];
|
mEtInputType = VCInputType.values()[inputType];
|
||||||
|
Log.i("main", "mEtInputType:" + mEtInputType);
|
||||||
mEtWidth = typedArray.getDimensionPixelSize(R.styleable.vericationCodeView_vcv_et_width, 120);
|
mEtWidth = typedArray.getDimensionPixelSize(R.styleable.vericationCodeView_vcv_et_width, 120);
|
||||||
mEtTextColor = typedArray.getColor(R.styleable.vericationCodeView_vcv_et_text_color, Color.BLACK);
|
mEtTextColor = typedArray.getColor(R.styleable.vericationCodeView_vcv_et_text_color, Color.BLACK);
|
||||||
mEtTextSize = typedArray.getDimensionPixelSize(R.styleable.vericationCodeView_vcv_et_text_size, 16);
|
mEtTextSize = typedArray.getDimensionPixelSize(R.styleable.vericationCodeView_vcv_et_text_size, 16);
|
||||||
mEtTextBg = typedArray.getResourceId(R.styleable.vericationCodeView_vcv_et_bg, R.drawable.et_login_code);
|
mEtTextBg = typedArray.getResourceId(R.styleable.vericationCodeView_vcv_et_bg, R.drawable.et_login_code);
|
||||||
mCursorDrawable = typedArray.getResourceId(R.styleable.vericationCodeView_vcv_et_cursor, R.drawable.et_cursor);
|
mCursorDrawable = typedArray.getResourceId(R.styleable.vericationCodeView_vcv_et_cursor, R.drawable.et_cursor);
|
||||||
|
cursorVisible = typedArray.getBoolean(R.styleable.vericationCodeView_vcv_et_cursor_visible, true);
|
||||||
//释放资源
|
//释放资源
|
||||||
typedArray.recycle();
|
typedArray.recycle();
|
||||||
initView();
|
initView();
|
||||||
@@ -177,10 +194,11 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
editText.setLayoutParams(layoutParams);
|
editText.setLayoutParams(layoutParams);
|
||||||
editText.setGravity(Gravity.CENTER);
|
editText.setGravity(Gravity.CENTER);
|
||||||
editText.setId(i);
|
editText.setId(i);
|
||||||
editText.setCursorVisible(true);
|
editText.setCursorVisible(false);
|
||||||
editText.setMaxEms(1);
|
editText.setMaxEms(1);
|
||||||
editText.setTextColor(mEtTextColor);
|
editText.setTextColor(mEtTextColor);
|
||||||
editText.setTextSize(mEtTextSize);
|
editText.setTextSize(mEtTextSize);
|
||||||
|
editText.setCursorVisible(true);
|
||||||
editText.setMaxLines(1);
|
editText.setMaxLines(1);
|
||||||
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1)});
|
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1)});
|
||||||
switch (mEtInputType) {
|
switch (mEtInputType) {
|
||||||
@@ -204,11 +222,13 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
editText.setBackgroundResource(mEtTextBg);
|
editText.setBackgroundResource(mEtTextBg);
|
||||||
|
|
||||||
//修改光标的颜色(反射)
|
//修改光标的颜色(反射)
|
||||||
try {
|
if (cursorVisible) {
|
||||||
Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
|
try {
|
||||||
f.setAccessible(true);
|
Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
|
||||||
f.set(editText, mCursorDrawable);
|
f.setAccessible(true);
|
||||||
} catch (Exception ignored) {
|
f.set(editText, mCursorDrawable);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
editText.addTextChangedListener(this);
|
editText.addTextChangedListener(this);
|
||||||
editText.setOnFocusChangeListener(this);
|
editText.setOnFocusChangeListener(this);
|
||||||
@@ -260,7 +280,9 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
editText = (EditText) getChildAt(i);
|
editText = (EditText) getChildAt(i);
|
||||||
if (editText.getText().length() < 1) {
|
if (editText.getText().length() < 1) {
|
||||||
editText.setCursorVisible(true);
|
if (cursorVisible) {
|
||||||
|
editText.setCursorVisible(true);
|
||||||
|
}
|
||||||
editText.requestFocus();
|
editText.requestFocus();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -281,7 +303,9 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
|||||||
editText = (EditText) getChildAt(i);
|
editText = (EditText) getChildAt(i);
|
||||||
if (editText.getText().length() >= 1) {
|
if (editText.getText().length() >= 1) {
|
||||||
editText.setText("");
|
editText.setText("");
|
||||||
editText.setCursorVisible(true);
|
if (cursorVisible) {
|
||||||
|
editText.setCursorVisible(true);
|
||||||
|
}
|
||||||
editText.requestFocus();
|
editText.requestFocus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,7 @@
|
|||||||
<attr name="vcv_et_bg" format="reference" />
|
<attr name="vcv_et_bg" format="reference" />
|
||||||
<!--光标样式-->
|
<!--光标样式-->
|
||||||
<attr name="vcv_et_cursor" format="reference" />
|
<attr name="vcv_et_cursor" format="reference" />
|
||||||
|
<!--是否隐藏光标-->
|
||||||
|
<attr name="vcv_et_cursor_visible" format="boolean" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user