2 qq 33815671 qq_33815671 于 2016.04.09 14:08 提问

android EditText输密码时怎么把圆点改成*号

android 用EditText输密码时,显示的是原点,怎么能把圆点改成*号呢

4个回答

q610098308
q610098308   2016.04.09 15:45
已采纳

需要转换一个显示;
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  
    }  
}  
Wei_Smile
Wei_Smile   2016.04.09 17:47

在EditText加入这么一行
android:inputType="passWord"

Wei_Smile
Wei_Smile passWord大小写可能有误,应该是password
一年多之前 回复
XDgaozhan
XDgaozhan   2016.04.11 00:02

设置一下inputType属性即可

android:id="@+id/password"
android:inputType="textPassword"/>

cyxevil
cyxevil   2016.04.13 10:39

fdhm_edit1.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);//密码不可见
fdhm_edit1.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);//密码可见

Csdn user default icon
上传中...
上传图片
插入图片