首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编辑文本密码总是显示密码。

问编辑文本密码总是显示密码。
EN

Stack Overflow用户
提问于 2017-03-29 11:25:45
回答 4查看 4.9K关注 0票数 2

我有一个EditText输入密码,并将inputType设置为"textPassword“。但是当我在app或模拟器中运行它时,密码是可见的。为什么它显示密码而不是点?

代码语言:javascript
复制
<EditText
 android:id="@+id/etPassword"
 android:layout_width="match_parent"
 android:inputType="textPassword"
 android:layout_height="wrap_content"
 android:hint="@string/Password"
 android:layout_marginBottom="10dp"
 android:maxLength="15"
 android:background="@drawable/ss"/>

可绘制文件ss:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<solid android:color="#ffffffff"/>
<stroke android:width="1dp" android:color="#CCCCCC" />

​

完整布局:

代码语言:javascript
复制
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:padding="10dp"
        android:orientation="vertical"
        android:layout_height="match_parent"
        android:background="#ffffffff"
        android:gravity="center_vertical" >

        <ImageView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/foodstall"
         android:layout_gravity="center"
         android:layout_marginBottom="10dp"/>

        <LinearLayout
         android:layout_width="match_parent"
         android:orientation="vertical"
         android:layout_height="wrap_content"
         android:background="#ffffffff">

        <EditText
        android:id="@+id/etUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/Username"
        android:maxLength="15"
        android:background="@drawable/ss"
        android:layout_marginBottom="10dp"/>

        <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:inputType="textPassword"
        android:layout_height="wrap_content"                                                     android:hint="@string/Password"
        android:layout_marginBottom="10dp"
        android:maxLength="15"
        android:background="@drawable/ss"
                android:text="askdjhkashdjasdksakdkaskdhkashkdhkashdkjhakshdkjhaskhdkj"/>

        <Button
        android:id="@+id/bLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title_activity_login"
        android:background="@color/button"
        android:textColor="#ffffffff"
        android:layout_weight="1" />

        </LinearLayout>

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearlayout"
        android:background="@drawable/ss"
        android:layout_marginTop="10dp">

        <TextView
        android:id="@+id/tvRegisterLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/Newuser"
        android:gravity="center"
        android:layout_weight="1"
        android:textStyle="bold"/>

        <TextView
        android:id="@+id/fpass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/title_activity_forgotpass"
        android:layout_weight="1"
        android:gravity="center"
        android:textStyle="bold"/>

        </LinearLayout>

        </LinearLayout>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-03-30 06:42:14

1)从xml文件中删除android:inputType="textPassword“,然后在java中设置它:

代码语言:javascript
复制
  EditText password = (EditText) findViewById(R.id.password_text);
  password.setTransformationMethod(new PasswordTransformationMethod());

使用这种方法,提示字体看起来很好,但是当您在编辑字段中键入时,在它变成密码点之前,您不会看到纯文本中的每个字符。同样,在全屏输入时,圆点不会出现,而是以明文形式出现。

2)将android:inputType="textPassword“保留在xml中。在Java中,passwordMethod:

代码语言:javascript
复制
  EditText password = (EditText) findViewById(R.id.register_password_text);
  password.setTransformationMethod(new PasswordTransformationMethod());

这种方法提供了密码点。

票数 5
EN

Stack Overflow用户

发布于 2017-03-29 11:33:58

尝试在android:password=中添加EditText“true”。应该管用的。

代码语言:javascript
复制
    <EditText
      android:id="@+id/etPassword"
      android:layout_width="match_parent"
      android:inputType="textPassword"
      android:password="true"
      android:layout_height="wrap_content"
      android:hint="@string/Password"
      android:layout_marginBottom="10dp"
      android:maxLength="15"
      android:background="@drawable/ss"/>
票数 2
EN

Stack Overflow用户

发布于 2017-03-29 11:36:25

我也遇到了这个问题,我的工作是:

我将这个xml属性添加到我的EditText中,它运行得很好:

代码语言:javascript
复制
android:singleLine="true"

我知道它不受欢迎,但android:maxLines="1"不起作用,尽管它取代了singleLine。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43092190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档