To set password enabled in EditText, We will have to set an "inputType" attribute in xml file.If we are using only EditText then we will have set input type in EditText as given in below code.
<EditText
android:id="@+id/password_Edit"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="100"
android:nextFocusDown="@+id/next"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Password enable attribute is
android:inputType="textPassword"
But if we are implementing Password EditText with Material Design (With Design support library) then we will have write code as given bellow.
<android.support.design.widget.TextInputLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/txtInput_currentPassword"
android:layout_width="match_parent"
app:passwordToggleEnabled="false"
android:layout_height="wrap_content">
<EditText
android:id="@+id/password_Edit"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="@string/hint_currentpassword"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="100"
android:nextFocusDown="@+id/next"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.TextInputLayout>
@Note: - In Android SDK 24 and above, "passwordToggleEnabled" is by default true. So if we have the customs handling of show/hide feature in the password EditText then we will have to set it false in code as given above in .
app:passwordToggleEnabled="true"
To add above line, we will have to add below line in root layout.
xmlns:app="http://schemas.android.com/apk/res-auto"
Password
is a real existing class, god beware one with static methods. – Tutto