Remove Delay for android textPassword

2019-05-30 03:29发布

问题:

While enterting password inside EditText view, Characters are being shown and after some delay it is shown as DOT, i want to remove this delay. It should be displayed directly as DOT.

How do i do this on Android?

回答1:

This is a user setting within Android, I do not believe that it is controllable from code. It is designed to aid the user in entering the correct password.

--Edit-- Further to the question askers comment, the setting can be found in:

Settings > Security > Make passwords visible

The above relates to Android ICS, the setting should be similar in previous versions.



回答2:

To Hide password forcefully,

android.provider.Settings.System.putInt(this.getContentResolver(),android.provider.Settings.System.TEXT_SHOW_PASSWORD, 0);

Note : It will not show any characters, Directly DOTs will be displayed without any delay inside your View having android:password attribute set to true



回答3:

Use code from AOSP PasswordTransformationMethod.java and modify it to suit your needs. Create new class MyPasswordTransformationMethod from it and modify the Visible class inside it. It would also need to change rest of the code because it accesses some private properties, but they are mostly constants so it is quite easy.

private static class Visible
extends Handler
implements UpdateLayout, Runnable
{
    public Visible(Spannable sp, MyPasswordTransformationMethod ptm) {
        mText = sp;
        mTransformer = ptm;
        //postAtTime(this, SystemClock.uptimeMillis() + 1500); 
        //replaced with following line
        postAtFrontOfQueue(this);
    }

    public void run() {
        mText.removeSpan(this);
    }

    private Spannable mText;
    private MyPasswordTransformationMethod mTransformer;
}