我有一个EditText
,其inputType
为numberPassword
。我想要更改替换文本的点的大小。对于我的目的来说,它(Android 默认值)相当小。我想增大点的大小。如何实现?
我有一个EditText
,其inputType
为numberPassword
。我想要更改替换文本的点的大小。对于我的目的来说,它(Android 默认值)相当小。我想增大点的大小。如何实现?
尝试用这些 ASCII 码替换星号:
⚫ - ⚫ - 中等大小的黑色圆圈
⬤ - ⬤ - 大黑色圆圈
如何在字符中间插入大圆点符号的 Unicode 字符是什么?
public class MyPasswordTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return new PasswordCharSequence(source);
}
private class PasswordCharSequence implements CharSequence {
private CharSequence mSource;
public PasswordCharSequence(CharSequence source) {
mSource = source; // Store char sequence
}
public char charAt(int index) {
return '*'; // This is the important part
}
public int length() {
return mSource.length(); // Return default
}
public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end); // Return default
}
}
};
text.setTransformationMethod(new MyPasswordTransformationMethod());
/**
* A transformation to increase the size of the dots displayed in the text.
*/
private object BiggerDotPasswordTransformationMethod : PasswordTransformationMethod() {
override fun getTransformation(source: CharSequence, view: View): CharSequence {
return PasswordCharSequence(super.getTransformation(source, view))
}
private class PasswordCharSequence(
val transformation: CharSequence
) : CharSequence by transformation {
override fun get(index: Int): Char = if (transformation[index] == DOT) {
BIGGER_DOT
} else {
transformation[index]
}
}
private const val DOT = '\u2022'
private const val BIGGER_DOT = '●'
}
Kotlin中更加简单。您不需要创建一个单独的类来覆盖单个方法。在Kotlin中,您可以这样做:
val passwordTransformation = object: PasswordTransformationMethod() {
override fun getTransformation(
source: CharSequence?,
view: View?
): CharSequence {
return super.getTransformation(source, view).replace(Regex("\u2022"), "●")
}
}
使用方法如下:
textView?.transformationMethod = passwordTransformation
尝试使用这个
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/etPasswordLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="password"
android:padding="0dp"
android:textSize="40dp"
android:background="@color/white"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>