更改密码的EditText面膜字符星号(*) [英] Change EditText password mask character to asterisk (*)
本文介绍了更改密码的EditText面膜字符星号(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法来改变从点的密码文本(。),以星号(*)。
密码是进入的EditText。
<的EditText
机器人:ID =@ + ID /密码1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=中心
机器人:inputType =数字
机器人:密码=真/>
在此先感谢。
得到与下面的链接帮助张贴拉姆基兰
答案答案
text.setTransformationMethod(新AsteriskPasswordTransformationMethod());
公共类AsteriskPasswordTransformationMethod扩展PasswordTransformationMethod {
@覆盖
公共CharSequence的getTransformation(CharSequence的源代码,查看查看){
返回新PasswordCharSequence(源);
}
私有类PasswordCharSequence实现的CharSequence {
私人的CharSequence mSource;
公共PasswordCharSequence(CharSequence的源){
mSource =来源; //保存字符序列
}
公共字符的charAt(INT指数){
返回 ''; //这是重要的组成部分
}
公众诠释长度(){
返回mSource.length(); //返回默认值
}
公共CharSequence的子进程(INT开始,诠释完){
返回mSource.subSequence(起点,终点); //返回默认值
}
}
};
解决方案
<的EditText
机器人:ID =@ + ID /密码1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=中心
机器人:inputType =textPassword//这里的变化。在你的XML一次检查
机器人:密码=真/>
在Eclipse中会有提示,当您点击<大骨节病>控制骨节病> + <大骨节病>空格骨节病>当你移动光标在安卓inputType
。然后你就可以看到选项列表。在那里,你可以选择 textPassword
如果你想看到 *
代替的
再查这个的 安卓星号密码字段
Is there any way to change the password text from dot(.) to asterisk(*) .
Password is entering in 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"/>
Thanks in advance.
Got answer with help of following link posted by Ram kiran
answer is
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
}
}
};
解决方案
<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"/>
In eclipse there will be hints when you click Ctrl + Space when you move cursor at android:inputType
. Then you can see list of options. there you can select textPassword
If you want to see *
in place of .
then check this Android: Asterisk Password Field
这篇关于更改密码的EditText面膜字符星号(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文