代码已经整理好,效果如下图:

    code:

        //设置输入为密码模式
        inputETP1.setInputType(InputType.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
        inputETP1.setDrawableRightListener(new EditTextPassword.DrawableRightListener() {
            @Override
            public void onDrawableRightClick() {
                //同样地可以在这可以实现其他的效果,比如一键清空
                if (mIsShow1) {
                    inputETP1.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.eye_grey, 0);
                    inputETP1.setInputType(InputType.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
                } else {
                    inputETP1.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.eye_orange, 0);
//                    inputETP.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                    inputETP1.setInputType(InputType.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_NORMAL);
                }
                mIsShow1 = !mIsShow1;
            }
        });

    Android Studio 第五十三期 - 自定义EditText密码键盘_第1张图片

    地址:https://github.com/geeklx/MyApplication/tree/master/p039_edittextpwd