Reputation: 219
I have a login activity for my android app. 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"
. 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 :)
Upvotes: 3
Views: 4557
Reputation: 1214
You need TextInputLayout and 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>
Upvotes: 6
Reputation: 560
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>
Upvotes: 0
Reputation: 93708
You need to use a TextInputLayout, not an EditText. EditText is a simpler UI element with fewer features. TextInputLayout includes an EditText and various other views.
Upvotes: 0