how to change visiblity (visible, invisible or gone ) of setEndIconDrawable in TextInputLayout android?

断了今生、忘了曾经 提交于 2020-07-10 03:12:42

问题


I am trying to make invisible or visibility gone of endIconDrawable which is the edit icon in the picture above for FirstName field only and want to keep visibile edit icon rest of the fields but unable to do? How can i do this?

      <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/tilFirstName"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_64dp"
                app:endIconDrawable="@drawable/icon_edit"
                app:endIconMode="custom">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/etFirstName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:focusableInTouchMode="false"
                    android:hint="@string/label_fname"
                    android:inputType="textCapWords" />
            </com.google.android.material.textfield.TextInputLayout>

I wanted to get the following as shown in the below image:


回答1:


If you want to do it in the layout (static way) just don't add the app:endIconDrawable/app:endIconMode attributes:

  <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/tilFirstName"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_64dp">

Programmatically to remove the endIconDrawable you can use:

textInputLayout.setEndIconMode(TextInputLayout.END_ICON_NONE);

To add the endIconDrawable you can use:

textInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
textInputLayout.setEndIconDrawable(R.drawable.xxxx);



回答2:


Add this android:visibility="gone"



来源:https://stackoverflow.com/questions/62789319/how-to-change-visiblity-visible-invisible-or-gone-of-setendicondrawable-in-t

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