Android TextInputLayout Password toggle not visible in new support library

六月ゝ 毕业季﹏ 提交于 2021-02-17 21:34:05

问题


I have compiled with following design library and it is displaying password HIDE/SHOW button at the right of EditText

compile 'com.android.support:design:24.2.1'

<android.support.design.widget.TextInputLayout
    android:id="@+id/login_password_text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/spacing_normal">

    <android.support.v7.widget.AppCompatEditText
        android:id="@+id/login_password_edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawablePadding="@dimen/spacing_micro"
        android:hint="@string/prompt_password"
        android:imeActionId="@+id/login"
        android:imeActionLabel="@string/action_sign_in_short"
        android:imeOptions="actionUnspecified"
        android:inputType="textPassword"
        android:maxLines="1"
        android:text="password" />

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

like:

after updating to

compile 'com.android.support:design:25.0.1'

Its not visible, Why? Is there any bug?

Please guide.


回答1:


The TextInputLayout password toggle is now disabled by default to avoid unnecessarily overwriting developer-specified end drawables. It may be manually enabled via the passwordToggleEnabled XML attribute.

from https://developer.android.com/topic/libraries/support-library/revisions.html




回答2:


I smashed my head with this one for hours.

From the release notes: https://developer.android.com/topic/libraries/support-library/revisions.html#

Fixed issues: The TextInputLayout password toggle is now disabled by default to avoid unnecessarily overwriting developer-specified end drawables. It may be manually enabled via the passwordToggleEnabled XML attribute.

So to have it back, you have to:

 <android.support.design.widget.TextInputLayout
    ...
    ...
    app:passwordToggleEnabled="true">

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

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



回答3:


It is disabled in 25.0.1. If you want it, you need to manually enable it

Check reference here

The TextInputLayout password toggle is now disabled by default to avoid unnecessarily overwriting developer-specified end drawables. It may be manually enabled via the passwordToggleEnabled XML attribute.




回答4:


The TextInputLayout password toggle is now disabled by default to avoid unnecessarily overwriting developer-specified end drawables. It may be manually enabled via the passwordToggleEnabled XML attribute.

see revision for 25.0.1

Note : Every developer must see the revision document.




回答5:


Using This

app:passwordToggleEnabled="true"  in TextInputLayout

and change dependency

compile 'com.android.support:appcompat-v7:26.0.1'

Setting up Gradle for api 26 (Android)

  <android.support.design.widget.TextInputLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textInputLayout2"
                android:layout_marginLeft="@dimen/box_layout_margin_left"
                android:layout_marginRight="@dimen/box_layout_margin_right"
                android:padding="@dimen/text_input_padding"
                app:passwordToggleEnabled="true">

                <EditText
                    android:id="@+id/et_password"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:drawableLeft="@android:drawable/ic_lock_lock"
                    android:drawablePadding="10dp"
                    android:paddingLeft="35dp"
                    android:gravity="top"
                    android:hint="Password"
                    android:inputType="textPassword"
                    android:paddingRight="@dimen/edit_input_padding"
                    android:paddingTop="5dp"
                    android:singleLine="true">
                </EditText>

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



回答6:


Add endIconMode to Custom for adding drawable end for a textinputlayout.

<com.google.android.material.textfield.TextInputLayout app:endIconMode="custom" app:endIconDrawable="@drawable/ic_tick_grey" .... </com.google.android.material.textfield.TextInputLayout>



来源:https://stackoverflow.com/questions/41098475/android-textinputlayout-password-toggle-not-visible-in-new-support-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!