接上篇,优化了一下代码,添加一些属性;
"space" //每个输入框之间的间距;
"strokeWidth" //边框的高度;
"checkedColor" //已输入的颜色
"defaultColor" //未输入的默认颜色
"textLength" //规定输入长度
"backColor" //输入框的背景颜色
"textColor" //字体颜色
"circle" //密文密码 ● 的大小;
"round" //输入框的圆角弧度
"textSize" //字体大小
"isPwd" //是否密文输入 默认true
"waitInputColor" //待输入线的颜色
"isWaitInput" //是否显示待输入线 默认false
GiaHub源码 : https://github.com/CuiChenbo/PwdInputEditText
如何使用:
public class MainActivity extends AppCompatActivity {
private PwdEditText p;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
p = findViewById(R.id.p);
p.setOnTextChangeListener(new PwdEditText.OnTextChangeListener() {
@Override
public void onTextChange(String pwd) {
if (pwd.length() == p.getTextLength()){
//输入监听
Toast.makeText(MainActivity.this,pwd,Toast.LENGTH_SHORT).show();
}
}
});
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
p.clearText(); //清空输入内容
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<c.c.b.pwdinputedittext.PwdEditText
android:id="@+id/p"
android:layout_centerInParent="true"
android:layout_width="330dp"
android:layout_height="wrap_content"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="清空"
android:id="@+id/btn"
android:layout_below="@id/p"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
看代码,PwdEditText :
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.gra