更改密码的EditText面膜字符星号(*)(Change EditText password ma

2019-07-17 15:27发布

有没有什么办法来改变从点密码文本(。),以星号(*)。

密码进入的EditText。

<EditText
        android:id="@+id/passWord1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:inputType="number"
        android:password="true"/>

Answer 1:

在XML文件中插入的EditText,

<EditText
    android:id="@+id/passWordEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:inputType="textPassword"/>

和你的类文件去和从EditText上获得findViewById和实施这一点,

EditText edittext = (EditText)findViewById(R.id.passWordEditText);
edittext.setTransformationMethod(new AsteriskPasswordTransformationMethod());

这个类实现为,

public class AsteriskPasswordTransformationMethod 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
        }
    }
};


Answer 2:

<EditText
        android:id="@+id/passWord1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:inputType="textPassword"//here is the change. check it once in your xml
        android:password="true"/>

在Eclipse中会有提示,当你点击Ctrl + 空格 ,当你将光标移动android:inputType 。 然后,你可以看到的选项列表。 在那里,你可以选择textPassword

如果你想看到*代替. 然后检查这个Android: Asterisk Password Field



Answer 3:

得到的答案与链接的帮助下发表拉姆基兰

text.setTransformationMethod(new AsteriskPasswordTransformationMethod());


public class AsteriskPasswordTransformationMethod 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
    }
}
};


Answer 4:

针对Android:的inputType,有一种类型的密码。



Answer 5:

访问计算器的这个问题,它会回答你的问题

如何更改密码字段diplay星号代替点



Answer 6:

试试这个

android:inputType="textPassword"       


Answer 7:

检查下面的链接: -

如果你想看到*代替。 然后检查这个Android:星号密码字段

http://codemanteau.com/post/code_11



Answer 8:

EditText.setTransformationMethod(new PasswordTransformationMethod());


文章来源: Change EditText password mask character to asterisk (*)