android 让EditText中输入的字符立即变成*或者其他符号

1.
public class WordReplacement extends ReplacementTransformationMethod {
    String strWord = null;
    @Override
    protected char[] getOriginal() {
        //循环ASCII值 字符串形式累加到String
        for (char i = 0; i < 256; i++) {
            strWord += String.valueOf(i);
        }
        //strWord转换为字符形式的数组
        char[] charOriginal = strWord.toCharArray();
        return charOriginal;
    }
    @Override
    protected char[] getReplacement() {
        char[] charReplacement = new char[255];
        //输入的字符在ASCII范围内,将其转换为*
        for (int i = 0; i < 255; i++) {
            charReplacement[i] = '.';
        }
        return charReplacement;
    }
}

2.

editText.setTransformationMethod(new WordReplacement());
    原文作者:tergun
    原文地址: https://blog.csdn.net/tierong/article/details/89467526
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞