将密码文本转换为星号后放置一个空格 [英] Put a space after transforming the password text into asterisks

查看:30
本文介绍了将密码文本转换为星号后放置一个空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用下面的 passwordTransformationClass 以星号格式显示密码.问题是,我希望在编辑文本中的每个文本之后都有一个空格,即每个星号之后都有一个空格.但是被覆盖的方法除了一个星号字符外不占用空间.

In my application, I am using the below passwordTransformationClass for showing the password in asterisk format. The problem is, I want a space after each text in the edit text, i.e. a space after every asterisk. But the overridden methods don’t take space except a single asterisk character.

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
        }
    }
}

推荐答案

Input : <*****>

Input : <*****>

我希望这是您在 EditTextView 中的输入,并且您想将 EditTextView 文本转换为类似的内容

I hope this is your input in EditTextView and you want to transform the EditTextView text to something like

输出:<* * * * *>

Output: <* * * * *>

然后设置一些自定义的 EditTextView 字体,这些字体在字符之间有很大的间距...

then set some custom EditTextView fonts which have much spacing between characters...

在 Android 中更改 EditText 的字体?

如果你正在通过Editext.addTextChangedListener,我们可以做到,但我们必须在其中写下一些昂贵的逻辑处理复制、粘贴、退格和许多其他情况.. :)

and if you are going through Editext.addTextChangedListener, we can do it but we have to write down some expensive Logics into it to handle copy, paste, backspace and so many other cases .. :)

这篇关于将密码文本转换为星号后放置一个空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆