如何在android

时间:2018-01-09 06:53:25

标签: android android-edittext android-inputtype

我有一个EditText inputTypenumberPassword。我想更改替换文本的点大小。它对我来说非常小(android默认)。我想增加点大小。我怎样才能做到这一点?

3 个答案:

答案 0 :(得分:8)

尝试用此ascii代码替换星号 ⚫ - ⚫ - 中黑圈 ⬤ - &#11044 - 黑色大圆圈

What would be the Unicode character for big bullet in the middle of the character?

 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());

答案 1 :(得分:2)

该解决方案提供了一半的效果,问题在于转换将文本直接转换为“ *”,而预期的行为是在输入新字符后或几秒钟后隐藏字符,以便用户获得隐藏它之前有机会看到真正的字符。如果要保留默认行为,则应执行以下操作:

/**
 * 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 = '●'
}

这将用您想要的任何字符替换原始点。

答案 2 :(得分:0)

尝试使用此

<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>