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
相关产品推荐
相关产品推荐

