You need to enable JavaScript to run this app. 如何移除嵌套在TextInputLayout中AutoCompleteTextView的默认外边框
优惠活动
大模型
产品
解决方案
定价
更多

如何移除嵌套在TextInputLayout中AutoCompleteTextView的默认外边框

问题根源

你使用的@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu样式本身自带顶层绘制的外描边,该描边由TextInputLayout自身渲染,优先级高于你设置的背景,所以修改子View或父View的背景都无法覆盖/隐藏该描边。之前设置boxStroke属性不生效,是因为缺少了宽度和背景模式的配套配置。

解决方案

方法1:替换为无描边样式(推荐)

直接使用不带默认描边的TextInputLayout样式,和普通输入框保持一致的配置逻辑:

  1. 把州选择器的TextInputLayout的style替换为@style/Widget.MaterialComponents.TextInputLayout.None.ExposedDropdownMenu,该样式默认无自带背景和描边
  2. 移除TextInputLayout上的background属性,给子AutoCompleteTextView设置自定义背景@drawable/rounded_edittext_states
  3. 建议将原生AutoCompleteTextView替换为MaterialAutoCompleteTextView,避免Material组件样式兼容问题

修改后的代码示例:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/input_state"
    style="@style/Widget.MaterialComponents.TextInputLayout.None.ExposedDropdownMenu"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:visibility="@{viewModel.addDevice.isFinishedWithSettings ? View.INVISIBLE : View.VISIBLE}"
    app:endIconMode="dropdown_menu"
    app:hintEnabled="false"
    app:layout_constraintEnd_toStartOf="@id/input_zip_code"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/input_city">

    <com.google.android.material.textfield.MaterialAutoCompleteTextView
        android:id="@+id/input_state_edit_text"
        style="@style/AppFont500.DarkGrey.EditTextHint"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingStart="25dp"
        android:paddingEnd="25dp"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:layout_marginEnd="4dp"
        android:visibility="@{viewModel.addDevice.isFinishedWithSettings ? View.INVISIBLE : View.VISIBLE}"
        android:imeOptions="actionDone"
        android:inputType="none"
        android:text="@={viewModel.addDevice.state}"
        android:hint="@string/hint_state"
        android:background="@drawable/rounded_edittext_states"/>
</com.google.android.material.textfield.TextInputLayout>

方法2:保留原样式的前提下禁用描边

如果不想替换样式,可以在现有TextInputLayout上添加以下4个属性,强制关闭自带描边:

app:boxBackgroundMode="none"
app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"
app:boxStrokeColor="@android:color/transparent"

该方案不需要修改子View的配置,设置完成后你之前加在TextInputLayout上的自定义背景就可以正常显示,不会被描边遮挡。

内容的提问来源于stack exchange,提问作者Flash103

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 04:36:03