10

I have a TextInputEditText in conjunction with TextInputLayout with android:inputType="textPassword" using app:passwordToggleEnabled="true" to show password toggle button in the TextInputEditText like next image:

password toggle button example
The problem is once I press the password toggle button, it disappears for ever.
It was working well in com.android.support:design:24.2.0 version.

am I missing something new? it's a bug?

Some gradle project's setup:
minSdkVersion 17
targetSdkVersion 25
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:design:25.1.0'

Running in 2 different Android 6.0 (Marshmallow) devices.

XML:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/TextLabelGray"
    app:passwordToggleEnabled="true">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/profile_field_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/perfil_field_password"
        android:inputType="textPassword"
        android:maxLines="1"
        android:maxLength="100"
        android:imeOptions="actionNext"
        android:imeActionLabel="@string/perfil_field_tipo_documento"
        android:textColor="@color/colorAccent"
        android:textSize="@dimen/perfil_text_view_text_size"
        android:paddingStart="15dp"
        android:paddingEnd="5dp"/>
</android.support.design.widget.TextInputLayout>

If I use app:passwordToggleDrawable with a custom drawable in TextInputLayout it doesn't disappear.

The related style:

<style name="TextLabelGray" parent="TextAppearance.AppCompat">
    <!--//hint color And Label Color in False State-->
    <item name="android:textColorHint">@color/gray_text_color</item>
    <item name="android:textColorHighlight">@color/gray_text_color</item>
    <item name="android:textColorLink">@color/gray_text_color</item>
    <item name="colorAccent">@color/gray_text_color</item>
    <item name="colorControlNormal">@color/gray_text_color</item>
    <item name="colorControlActivated">@color/gray_text_color</item>
</style>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlNormal">@color/colorControlNormal</item>

    <item name="searchViewStyle">@style/AppTheme.MySearchViewStyle</item>
</style>
MiguelHincapieC
  • 5,445
  • 7
  • 41
  • 72
  • I had tried the same code and It is working.Please check the theme used once. – Android Geek Jan 03 '17 at 04:24
  • @AndroidGeek I tried without `android:theme="@style/TextLabelGray"` and what I found is the button does not disappears, it just got transparent, because I still can press it and have the hide/unhide password behavior. Tried with a black background but still getting same result. Any idea? – MiguelHincapieC Jan 03 '17 at 15:35
  • Playing with `TextInputLayout ` I found this: if I use a custom drawable in `app:passwordToggleDrawable` with `app:passwordToggleContentDescription` the button doesn't disappear – MiguelHincapieC Jan 03 '17 at 15:53
  • It is working fine without `theme="@style/TextLabelGray"`. So in order to help you we need to see that theme. – Divers Jan 03 '17 at 16:02
  • @AndroidGeek added. – MiguelHincapieC Jan 03 '17 at 16:11
  • I compiled it with `com.android.support:design:24.2.0` and it works like a charm... so I'm almost sure its a bug :S – MiguelHincapieC Jan 03 '17 at 16:16
  • 1
    damn! it's a bug [look this link](https://code.google.com/p/android/issues/detail?id=227917&can=1&q=TextInputLayout%20passwordtoggle&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened#makechanges) xD – MiguelHincapieC Jan 03 '17 at 16:27

3 Answers3

5

change gradle file by following dependency

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'

In xml file, add following lines for toggle button in password field

 <android.support.design.widget.TextInputLayout
 android:id="@+id/text_input_layout_password"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dp"
 app:passwordToggleEnabled="true">

          <android.support.design.widget.TextInputEditText
          android:id="@+id/text_input_edit_text_password"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:hint="Enter Password"
          android:imeActionId="@+id/login"
          android:imeActionLabel="Login"
          android:imeOptions="actionUnspecified"
          android:inputType="textPassword"
          android:maxLines="1"
          tools:text="password" />

 </android.support.design.widget.TextInputLayout>
Khyati Vara
  • 1,042
  • 13
  • 22
  • Hi there, ty for the answer but I think you need to check it in more real devices because it's a bug. Take a look at following [link](https://issuetracker.google.com/issues/37127113#makechanges). Is the same link that I posted in the question. – MiguelHincapieC Aug 17 '17 at 13:59
1

Add

<item name="passwordToggleDrawable">@drawable/design_password_eye</item>
<item name="passwordToggleTint">@color/design_tint_password_toggle</item>
<item name="passwordToggleContentDescription">@string/password_toggle_content_description</item>

on your TextLabelGray style and it will show toggle button again.

Nitesh Shrivas
  • 105
  • 1
  • 10
  • if it's working in all versions (26, 25, 24...) you should post it in [official issue page](https://issuetracker.google.com/issues/37127113) :D – MiguelHincapieC Apr 06 '18 at 16:02
0

This code work fine:

  <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16sp"
            app:passwordToggleEnabled="true"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prompt_password"
                android:imeActionId="6"
                android:inputType="textPassword"
                android:maxLines="1"
                android:fontFamily="@font/product_regular"
                android:singleLine="true" />

        </android.support.design.widget.TextInputLayout>


android {
compileSdkVersion 28
defaultConfig {
    applicationId "com"
    minSdkVersion 24
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

buildToolsVersion '28.0.2'

}

implementation 'com.android.support:exifinterface:28.0.0-rc02' 
implementation 'com.android.support:support-v4:28.0.0-rc02'
implementation 'com.android.support:support-v13:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc02'
implementation 'com.android.support:cardview-v7:28.0.0-rc02'
implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'