有没有什么办法来改变从点密码文本(。),以星号(*)。
密码进入的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"/>
在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
}
}
};
<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
得到的答案与链接的帮助下发表拉姆基兰
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
}
}
};
针对Android:的inputType,有一种类型的密码。
试试这个
android:inputType="textPassword"
检查下面的链接: -
如果你想看到*代替。 然后检查这个Android:星号密码字段
http://codemanteau.com/post/code_11
EditText.setTransformationMethod(new PasswordTransformationMethod());