从AutoCompleteTextView中移除下拉箭头

10
我想删除使用TextInputLayout并使用样式ExposedDropdownMenu时由AutoCompleteTextView创建的下拉箭头。

我想删除的图片

以下是我的代码:
<com.google.android.material.textfield.TextInputLayout
        android:layout_marginTop="10dp"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
        android:hint="Marital Status"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:boxStrokeColor="@color/colorPrimaryDark">

        <AutoCompleteTextView
            android:background="@null"
            android:focusable="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edt_marital" />
    </com.google.android.material.textfield.TextInputLayout>

这是AutoCompleteTextView。 - user6504610
@pskink 请也看一下我的代码,AutoCompletetextview 在这里的表现也是一样的,设计也相同。在这里看一下:https://material.io/develop/android/components/menu/ - user6504610
3个回答

28

如果您想避免下拉图标,请使用app:endIconMode属性。

<com.google.android.material.textfield.TextInputLayout
      style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
      app:endIconMode="none"
      ...>

之前和之后:

输入图片说明输入图片说明


4
设置 app:endIconMode="none" 后,下拉菜单未显示。 - Shams
@Shams你有解决方案吗? - Funny Moments
1
@Gabriele Mariotti,如果箭头消失了,菜单为什么不会显示出来呢? - Funny Moments

1
大家好,我在搜索很长时间后什么都没找到。尝试实现自己想要的效果,并想与大家分享经验和结果。 正如Material Design文档所说。
根据文档,得到一个类似Spinner的Image Dropdown Menu效果。下面是代码:
<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/txtAnswer"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin_top_15dp"
                android:layout_marginEnd="10dp"
                app:endIconDrawable="@drawable/ic_arrow_down"
                app:hintTextAppearance="@style/styleFilterLabelLatoRegular"
                app:layout_constraintEnd_toStartOf="@+id/txtAssignedTo"
                app:layout_constraintStart_toStartOf="@+id/guideLineBegin"
                app:layout_constraintTop_toBottomOf="@+id/txtSearchQuestionnaire">

                <AutoCompleteTextView
                    android:id="@+id/actvTypesAnswer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="none"
                    android:hint="@string/text_answer" />

现在从一个AutoCompleteTextView Image AutoCompleteTextView得到了预期的结果。代码xml。

<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/txtSearchQuestionnaire"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin_top_15dp"
                app:endIconMode="none"
                app:hintTextAppearance="@style/styleFilterLabelLatoRegular"
                app:layout_constraintEnd_toEndOf="@id/guideLineEnd"
                app:layout_constraintStart_toStartOf="@+id/guideLineBegin"
                app:layout_constraintTop_toBottomOf="@+id/txtPeriodActivation">

                <AutoCompleteTextView
                    android:id="@+id/actvNameQuestionnaire"
                    style="@style/textAppearanceSettingInputEdittextFilter.Enabled"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:drawableEnd="@drawable/ic_search"
                    android:hint="@string/text_search_name_questionnaire" />

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

唯一的更改是在TextInputLayout中添加属性app:endIconMode="none",并在AutoCompleteTextView中添加属性android:drawableEnd="@drawable/ic_search" 请原谅我的英语水平!!

0
除了在layout.xml中进行此操作外,还可以通过编程的方式来实现。因此,您需要一个周围TextInputLayout的实例,而不是AutoCompleteTextView
要删除下拉按钮,只需运行
textInputLayout.setEndIconMode(TextInputLayout.END_ICON_NONE);

激活下拉按钮,只需运行
textInputLayout.setEndIconMode(TextInputLayout.END_ICON_DROPDOWN_MENU);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接