我有一个EditText输入密码,并将inputType设置为"textPassword“。但是当我在app或模拟器中运行它时,密码是可见的。为什么它显示密码而不是点?
<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:
<?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" />
完整布局:
<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>发布于 2017-03-30 06:42:14
1)从xml文件中删除android:inputType="textPassword“,然后在java中设置它:
EditText password = (EditText) findViewById(R.id.password_text);
password.setTransformationMethod(new PasswordTransformationMethod());使用这种方法,提示字体看起来很好,但是当您在编辑字段中键入时,在它变成密码点之前,您不会看到纯文本中的每个字符。同样,在全屏输入时,圆点不会出现,而是以明文形式出现。
2)将android:inputType="textPassword“保留在xml中。在Java中,passwordMethod:
EditText password = (EditText) findViewById(R.id.register_password_text);
password.setTransformationMethod(new PasswordTransformationMethod());这种方法提供了密码点。
发布于 2017-03-29 11:33:58
尝试在android:password=中添加EditText“true”。应该管用的。
<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"/>发布于 2017-03-29 11:36:25
我也遇到了这个问题,我的工作是:
我将这个xml属性添加到我的EditText中,它运行得很好:
android:singleLine="true"我知道它不受欢迎,但android:maxLines="1"不起作用,尽管它取代了singleLine。
https://stackoverflow.com/questions/43092190
复制相似问题