我有一个应用程序,人们需要使用密码登录.我想只显示输入的最后一个字符,但我似乎得到的只是所有字符点或所有字符都可见.
我试了几件事:
@H_404_4@password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); password.setTransformationMethod(PasswordTransformationMethod.getInstance()); password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);并在xml中设置inputtype.
我只测试了一个星系s2,因为那是我办公室目前唯一的安卓设备,所以我不知道问题是否仅适用于我的设备.
编辑:
刚刚从一位同事的HTC Sensation上进行了测试,它确实可以在他的手机上运行,但问题仍然是如何在Galaxy S2上获得同样的东西?
解决方法
这被问到这已经差不多1.5年了:P.但我有同样的要求,并成功地实现了它.将MyTransformation类的对象作为setTransformationMethod中的参数传递,你很高兴:)这是代码.
@H_404_4@public class MyTransformation 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) {
//This is the check which makes sure the last character is shown
if(index != mSource.length()-1)
return '•';
else
return mSource.charAt(index);
}
public int length() {
return mSource.length(); // Return default
}
public CharSequence subSequence(int start,int end) {
return mSource.subSequence(start,end); // Return default
}
}
}