密码输入框

v1.5
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
dependencies {
compile 'com.github.EthanCo:PasswordInput:1.5.3'
}
在你的项目中加入PasswordInput Library,之后在xml使用即可
<com.ethanco.lib.PasswordInput
android:id="@+id/passwordInput_first"
android:layout_width="match_parent"
android:layout_height="56dp"
app:boxCount="6"
app:focusedColor="@color/colorAccent"
app:notFocusedColor="@color/colorPrimary" />
PasswordInput passwordInput = (PasswordInput) findViewById(R.id.passwordInput);
String pwdFirst = passwordInput.getText().toString();
passwordInput.setTextLenChangeListen(new PasswordInput.TextLenChangeListen() {
@Override
public void onTextLenChange(CharSequence text, int len) {
//do something
}
});
passwordInput.setPassword("123456")
passwordInput.setPassword("")
<attr name="focusedColor" format="color" />
<attr name="notFocusedColor" format="color" />
<attr name="backgroundColor" format="color" />
<attr name="boxCount" format="integer" />
<attr name="focusColorChangeEnable" format="boolean" />
<attr name="dotRaduis" format="dimension" />
PasswordDialog.Builder builder = new PasswordDialog.Builder(MainActivity.this)
.setTitle(R.string.please_input_password) //Dialog标题
.setBoxCount(4) //设置密码位数
.setBorderNotFocusedColor(R.color.colorSecondaryText) //边框颜色
.setDotNotFocusedColor(R.color.colorSecondaryText) //密码圆点颜色
.setPositiveListener(new OnPositiveButtonListener() {
@Override //确定
public void onPositiveClick(DialogInterface dialog, int which, String text) {
Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT).show();
}
})
.setNegativeListener(new DialogInterface.OnClickListener() {
@Override //取消
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();
}
})
.addCheckPasswordFilter(new CountCheckFilter()); //添加过滤器
builder.create().show();
可进行过滤器的添加,对于不符合输入要求的,返回为false,将不会执行NegativeListener回调。
public class CountCheckFilter implements ICheckPasswordFilter {
@Override
public boolean onCheckPassword(Context context, CharSequence password) {
if (password.length() != 4) {
Toast.makeText(context, "密码需为4位", Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
}
默认已添加密码为空情况的过滤器
builder.setPositiveText("确定");
builder.setNegativeText("取消");
builder.setBoxRadius(3); //单位为dp
buidler.setBoxMarge(3); //单位为dp
buidler.setBorderNotFocusedColor(R.color.colorSecondaryText)
.setDotNotFocusedColor(R.color.colorSecondaryText);
如需更改PositiveButton和NevegateButton的颜色,将
<color name="colorAccent">#FF4081</color>
复制到app的color.xml中修改即可。
builder..setCancelable(false);
将PasswordInput的tag设为passwordInput_dialog
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.ethanco.lib.PasswordInput
android:id="@+id/pwdInput_dialog"
android:layout_width="@dimen/dialog_password_input_width"
android:layout_height="@dimen/dialog_password_input_height"
android:layout_gravity="center"
android:layout_margin="8dp"
android:cursorVisible="false"
android:focusable="true"
android:inputType="number"
android:maxLength="4"
android:tag="passwordInput_dialog"
app:focusColorChangeEnable="false" />
</FrameLayout>
PasswordDialog.Builder builder = new
PasswordDialog.Builder(MainActivity.this, R.layout.custom_dialog_password);
$ claude mcp add PasswordInput \
-- python -m otcore.mcp_server <graph>