You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AutoCompleteTextView的Hint与Text样式不显示问题求助

AutoCompleteTextView的Hint与文本样式不显示问题

遇到AutoCompleteTextView的hint和文本样式不显示的问题,以下是构建该输入框的XML代码,错误截图如下:

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
    app:layout_constraintTop_toBottomOf="@id/from_tv"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginTop="8dp"
    android:hint="@string/select_country"
    >
    <AutoCompleteTextView
    android:id="@+id/from_auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
       android:text="amirican_dollar"
        />
</com.google.android.material.textfield.TextInputLayout>

错误截图

解决方案

  • 检查Material Components依赖:确保项目build.gradle中已引入Material库,比如添加implementation 'com.google.android.material:material:1.9.0'(版本可按需调整)。
  • 调整AutoCompleteTextView高度:将android:layout_height="match_parent"改为android:layout_height="wrap_content",或使用android:layout_height="?attr/materialTextFieldDefaultHeight"匹配TextInputLayout默认高度,避免布局冲突遮挡文本。
  • 为AutoCompleteTextView添加Material样式:在标签内添加style="@style/Widget.MaterialComponents.AutoCompleteTextView.OutlinedBox",确保组件应用对应样式。
  • 确认主题兼容性:App主题需继承MaterialComponents主题,比如在styles.xml中设置<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">,Material组件依赖该主题才能正常渲染样式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 18:22:16