[英]Want to show a password toggle/visible button in my android app
I have a login activity for my android app. 我的Android应用有登录活动。 Because of testing I typed in my password very often and sometimes I was not sure if its the right password so I need to delete it completely and typed it in again. 由于测试,我经常输入密码,有时我不确定密码是否正确,因此我需要将其完全删除并再次输入。 I think this is not design! 我认为这不是设计! I've searched a little bit and found out that there is a function called app:passwordToggleEnabled="true"
. 我搜索了一下,发现有一个名为app:passwordToggleEnabled="true"
的函数。 I have tried it but it throws an error. 我已经尝试过,但是会引发错误。
My code: 我的代码:
<EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPassword" android:ems="10" android:layout_marginTop="24dp" android:id="@+id/loginPassword" android:layout_below="@+id/loginEmail" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:hint="Passwort" android:selectAllOnFocus="false" android:textSize="18sp" android:textColorLink="#63c3c3" android:textColorHighlight="#63c3c3" android:textCursorDrawable="@null" android:backgroundTint="#63c3c3" android:passwordToggleEnabled="true" //HERE! android:cursorVisible="true" />
But I got an error.. 但是我出错了
Error:(14) No resource identifier found for attribute 'passwordToggleEnabled' in package 'android'
Thanks for helping me :) 感谢您的帮助:)
You need TextInputLayout and TextInputEditText 您需要TextInputLayout和TextInputEditText
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleContentDescription="description"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/colorAccent">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
You need to use a TextInputLayout, not an EditText. 您需要使用TextInputLayout,而不是EditText。 EditText is a simpler UI element with fewer features. EditText是功能更简单的UI元素。 TextInputLayout includes an EditText and various other views. TextInputLayout包含一个EditText和其他各种视图。
use this library it works fine for this purpose: 使用此库可以很好地实现此目的:
compile 'com.android.support:design:24.1.1'
Example: 例:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/txtUsername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/user"
android:drawableTint="#FF4081"
android:hint="User Name"
android:inputType="textEmailAddress"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.