qq_33815671
qq_33815671
采纳率73.7%
2016-04-09 06:08 阅读 2.8k

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

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    q610098308 恋恋西风 2016-04-09 07: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 李牧羊 2016-04-09 09:47

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

    点赞 评论 复制链接分享
  • XDgaozhan xdgaozhan 2016-04-10 16:02

    设置一下inputType属性即可

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

    点赞 评论 复制链接分享
  • cyxevil cyxevil 2016-04-13 02:39

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

    点赞 评论 复制链接分享

相关推荐