Android-如何使TextInputLayout endIcon始终可见?

问题描述 投票:0回答:1

我有一个带有clear text endIcon的TextInputLayout,但仅当TextInput具有焦点时(显示键盘时,该字符才可见。)>

只要字段中有输入,我希望明文图标始终可见。是否可以实现此行为?

这是我的xml:

<com.google.android.material.textfield.TextInputLayout
     style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:background="@drawable/search_view_background"
     app:endIconDrawable="@drawable/ic_close_black_24dp"
     app:endIconCheckable="true"
     app:endIconMode="clear_text"
     app:hintEnabled="false"
     app:startIconDrawable="@drawable/ic_search">

         <com.google.android.material.textfield.TextInputEditText
              android:id="@+id/search_edit_text"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="@drawable/empty"
              android:hint="@string/hint_socials_search"
              android:inputType="text"
              android:singleLine="true"
              android:textColor="?attr/colorOnSurface" />

</com.google.android.material.textfield.TextInputLayout>

感谢您的时间!

我有一个带有清晰文本endIcon的TextInputLayout,但是只有在TextInput具有焦点时(显示键盘时),它才可见。我希望明文图标始终显示为...

android xml android-textinputlayout
1个回答
0
投票

隐藏端图标是clear_text模式的默认行为,您无法覆盖它。我认为实现所需行为的最简单方法是:

© www.soinside.com 2019 - 2024. All rights reserved.