修改demo
This commit is contained in:
@@ -8,31 +8,44 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.jyn.vcview.VerificationCodeView;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
public class MainActivity extends AppCompatActivity implements VerificationCodeView.OnCodeFinishListener {
|
||||
|
||||
private TextView textView;
|
||||
private VerificationCodeView verificationcodeview;
|
||||
private TextView textView, textView2;
|
||||
private VerificationCodeView verificationcodeview, verificationcodeview2;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
verificationcodeview = findViewById(R.id.verificationcodeview);
|
||||
textView = findViewById(R.id.text);
|
||||
verificationcodeview.setOnCodeFinishListener(new VerificationCodeView.OnCodeFinishListener() {
|
||||
@Override
|
||||
public void onTextChange(View view, String content) {
|
||||
textView.setText("输入中:" + content);
|
||||
}
|
||||
verificationcodeview2 = findViewById(R.id.verificationcodeview2);
|
||||
|
||||
@Override
|
||||
public void onComplete(View view, String content) {
|
||||
textView.setText("输入结束:" + content);
|
||||
}
|
||||
});
|
||||
textView = findViewById(R.id.text);
|
||||
textView2 = findViewById(R.id.text2);
|
||||
verificationcodeview.setOnCodeFinishListener(this);
|
||||
verificationcodeview2.setOnCodeFinishListener(this);
|
||||
}
|
||||
|
||||
public void clear(View view) {
|
||||
verificationcodeview.setEmpty();
|
||||
verificationcodeview2.setEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChange(View view, String content) {
|
||||
if (view == verificationcodeview) {
|
||||
textView.setText("输入中:" + content);
|
||||
} else if (view == verificationcodeview2) {
|
||||
textView2.setText("输入中:" + content);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(View view, String content) {
|
||||
if (view == verificationcodeview) {
|
||||
textView.setText("输入结束:" + content);
|
||||
} else if (view == verificationcodeview2) {
|
||||
textView2.setText("输入结束:" + content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
19
simple/src/main/res/drawable/et_code_test1.xml
Normal file
19
simple/src/main/res/drawable/et_code_test1.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:state_window_focused="false">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#FFFFFF" />
|
||||
<stroke android:width="2dp" android:color="#C4C4C4" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:state_focused="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#ffffff" />
|
||||
<stroke android:width="2dp" android:color="#FFC107" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
@@ -7,6 +7,13 @@
|
||||
android:orientation="vertical"
|
||||
tools:context="com.jyn.vcview.simple.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text="输入框距离平分,未隐藏光标,明文密码" />
|
||||
|
||||
<com.jyn.vcview.VerificationCodeView
|
||||
android:id="@+id/verificationcodeview"
|
||||
android:layout_width="match_parent"
|
||||
@@ -16,8 +23,7 @@
|
||||
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_inputType="number"
|
||||
app:vcv_et_number="4"
|
||||
app:vcv_et_text_color="@android:color/black"
|
||||
app:vcv_et_text_size="6sp" />
|
||||
@@ -29,7 +35,46 @@
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="输入开始:" />
|
||||
android:text="输入未开始:" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@android:color/black" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="输入框间距6dp,隐藏光标,隐藏密码" />
|
||||
|
||||
<com.jyn.vcview.VerificationCodeView
|
||||
android:id="@+id/verificationcodeview2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
app:vcv_et_bg="@drawable/et_code_test1"
|
||||
app:vcv_et_cursor="@drawable/et_cursor"
|
||||
app:vcv_et_cursor_visible="false"
|
||||
app:vcv_et_inputType="numberPassword"
|
||||
app:vcv_et_number="6"
|
||||
app:vcv_et_spacing="6dp"
|
||||
app:vcv_et_text_color="#FFC107"
|
||||
app:vcv_et_text_size="6sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="输入未开始:" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.jyn.vcview;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@@ -18,6 +18,7 @@ import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
@@ -27,7 +28,7 @@ import java.lang.reflect.Field;
|
||||
* update 2019/8/8
|
||||
*/
|
||||
|
||||
public class VerificationCodeView extends LinearLayout implements TextWatcher, View.OnKeyListener {
|
||||
public class VerificationCodeView extends LinearLayout implements TextWatcher, View.OnKeyListener, View.OnFocusChangeListener {
|
||||
|
||||
private Context mContext;
|
||||
private OnCodeFinishListener onCodeFinishListener;
|
||||
@@ -217,8 +218,10 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
private void initEditText(EditText editText, int i) {
|
||||
editText.setLayoutParams(getETLayoutParams(i));
|
||||
editText.setTextAlignment(TextView.TEXT_ALIGNMENT_CENTER);
|
||||
editText.setGravity(Gravity.CENTER);
|
||||
editText.setId(i);
|
||||
editText.setCursorVisible(false);
|
||||
@@ -251,6 +254,7 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
||||
setEditTextCursorDrawable(editText);
|
||||
editText.addTextChangedListener(this);
|
||||
editText.setOnKeyListener(this);
|
||||
editText.setOnFocusChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,8 +276,8 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
||||
layoutParams.rightMargin = mEtBisectSpacing / 2;
|
||||
}
|
||||
} else {
|
||||
layoutParams.leftMargin = mEtSpacing;
|
||||
layoutParams.rightMargin = mEtSpacing;
|
||||
layoutParams.leftMargin = mEtSpacing / 2;
|
||||
layoutParams.rightMargin = mEtSpacing / 2;
|
||||
}
|
||||
|
||||
layoutParams.gravity = Gravity.CENTER;
|
||||
@@ -299,16 +303,6 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
||||
updateETMargin();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
super.onLayout(changed, l, t, r, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
private void updateETMargin() {
|
||||
for (int i = 0; i < mEtNumber; i++) {
|
||||
EditText editText = (EditText) getChildAt(i);
|
||||
@@ -316,6 +310,14 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean b) {
|
||||
if (b) {
|
||||
focus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<size android:width="2dp" />
|
||||
<size android:width="1dp" />
|
||||
<solid android:color="#0dbc75" />
|
||||
</shape>
|
||||
Reference in New Issue
Block a user