为什么显示InputType密码?

时间:2017-08-07 10:46:28

标签: android input passwords maskededitextender

我的代码:

final EditText input = new EditText(VideoRunActivity.this);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        input.setLayoutParams(lp);
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

显示我输入的输入。提前谢谢。

3 个答案:

答案 0 :(得分:1)

尝试这样做:

input.setTransformationMethod(PasswordTransformationMethod.getInstance());

所以代码就是这样:

    final EditText input = new EditText(VideoRunActivity.this);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT);
            input.setLayoutParams(lp);
            input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
input.setTransformationMethod(PasswordTransformationMethod.getInstance());

答案 1 :(得分:0)

XML

中试试
<EditText
        android:id="@+id/txtPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword" >
</EditText>

答案 2 :(得分:0)

试试这个

input.setTransformationMethod(new PasswordTransformationMethod());