【问题标题】:inputType doesn't hide the passwordinputType 不隐藏密码
【发布时间】:2016-01-24 11:34:25
【问题描述】:

我在EditText中设置了属性android:inputType

android:inputType="textWebPassword"` 

但它仍然显示我输入的密码。 还有其他(或替代)应该做的事情吗?

 android:layout_width="match_parent"
 android:layout_height="@dimen/button_height"
 android:background="@drawable/background_edit"
 android:ems="10"
 android:gravity="center"
 android:hint="@string/new_pass_hint"
 android:inputType="textWebPassword"
 android:textColor="@color/edit_text_text_color"
 android:textColorHint="@color/edt_text_hint_color"
 android:textSize="@dimen/button_text_size"

【问题讨论】:

    标签: android android-edittext passwords android-inputtype


    【解决方案1】:

    请试试这个

    Edttext.setTransformationMethod(PasswordTransformationMethod.getInstance());
    

    然后这个在你的布局中

    android:password="true"
    

    【讨论】:

    • 它几乎修复了它。第一个字母是 unhidden ,然后在键入第二个字母后它是隐藏的。无论如何我都会接受你的回答,但你知道为什么它只在第二个字母之后有效吗?
    • 是的,我知道第一个代码使其不隐藏,但是除非添加第一个代码,否则第二个代码不起作用..setTransformationMethod 是设置输入类型的编程方式。所以我们将其设置为 PasswordTransformationMethod然后选择是否要在布局中隐藏它。谢谢!
    【解决方案2】:

    应该是textPassword 看看this

    <EditText
     android:id="@+id/edtPassword"
     android:layout_width="fill_parent"
     android:layout_height="42dp"
     android:layout_marginTop="16dp"
     android:hint="Password"
     android:inputType="textPassword"
     android:padding="5dip"
     android:singleLine="true"
     android:textColor="#363435"
     android:textSize="14sp" />
    

    【讨论】:

    • 代码不多,我只是用了一个TextWatcher public void afterTextChanged(Editable s) { if(s.length()==0){ edtPass.setBackgroundResource(R.drawable.background_edit); }else { edtPass.setBackgroundResource(R.drawable.text_background); }
    • 我需要它 textWebPassword 因为我使用处理所有请求的服务器.. 但无论如何,这个或 textPassword 似乎也出于某种原因工作。我已经编辑了原始帖子以显示 xml。谢谢。
    【解决方案3】:

    你必须设置

    android:password="true"

    【讨论】:

    • 那不是被弃用的吗?还是我弄错了?谢谢。
    • 嗯......似乎已弃用......但它不是隐藏密码吗?正如我最近使用的那样,它对我有用。
    猜你喜欢
    • 2021-05-20
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 2013-12-20
    • 2014-08-10
    • 2021-08-25
    相关资源
    最近更新 更多