inputType="password",font changed

来源:互联网 发布:log4j 日志写入数据库 编辑:程序博客网 时间:2024/06/11 21:43

项目中遇到金立手机,修改密码时,密码输入框hint文字英文符号字体不一致;
跳转到TextView中setInputType 方法,为password时设置的MONOSPACE;
所以只需要在代码中重新设置Typeface,setTypeface(Typeface.DEFAULT)

public void setInputType(int type) {        final boolean wasPassword = isPasswordInputType(getInputType());        final boolean wasVisiblePassword = isVisiblePasswordInputType(getInputType());        setInputType(type, false);        final boolean isPassword = isPasswordInputType(type);        final boolean isVisiblePassword = isVisiblePasswordInputType(type);        boolean forceUpdate = false;        if (isPassword) {            setTransformationMethod(PasswordTransformationMethod.getInstance());            setTypefaceFromAttrs(null /* fontFamily */, MONOSPACE, 0);        } else if (isVisiblePassword) {            if (mTransformation == PasswordTransformationMethod.getInstance()) {                forceUpdate = true;            }            setTypefaceFromAttrs(null /* fontFamily */, MONOSPACE, 0);        } else if (wasPassword || wasVisiblePassword) {            // not in password mode, clean up typeface and transformation            setTypefaceFromAttrs(null /* fontFamily */, -1, -1);            if (mTransformation == PasswordTransformationMethod.getInstance()) {                forceUpdate = true;            }        }       //........    }
private void setTypefaceFromAttrs(String familyName, int typefaceIndex, int styleIndex) {        Typeface tf = null;        if (familyName != null) {            tf = Typeface.create(familyName, styleIndex);            if (tf != null) {                setTypeface(tf);                return;            }        }        switch (typefaceIndex) {            case SANS:                tf = Typeface.SANS_SERIF;                break;            case SERIF:                tf = Typeface.SERIF;                break;            case MONOSPACE:                tf = Typeface.MONOSPACE;                break;        }        setTypeface(tf, styleIndex);    }
原创粉丝点击