android - 如何调整 AutoCompleteTextView 的样式以匹配 TextInputEditText 的样式
问题描述
我有一个AutoCompleteTextView
包裹在一个com.google.android.material.textfield.TextInputLayout
和填充和大小都是错误的。
没有任何填充:
和弹出窗口
从上图中可以看出,State字段的大小不合适,但弹出窗口大小合适。
所以我CustomAutoCompleteTextView
在styles.xml 中创建了一个来整理它,但我得到了这个:
当我添加自定义样式时,弹出窗口也会受到影响。
AutoCompleteTextView
设置样式以匹配其他标准的正确方法是什么TextInputEditText
?
布局.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_rounded_corners"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilTag"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:endIconMode="clear_text"
app:layout_constraintEnd_toStartOf="@id/tilState"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etTag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/tag"
android:singleLine="true"
android:theme="@style/EditTextField" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilState"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:theme="@style/EditTextField"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tilTag"
app:layout_constraintTop_toTopOf="parent">
<AutoCompleteTextView
android:id="@+id/etState"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:hint="@string/state"
android:theme="@style/CustomAutoCompleteTextView"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
样式.xml
<style name="EditTextField">
<item name="colorControlNormal">@color/editTextDefault</item>
<item name="colorControlActivated">@color/editTextActive</item>
<item name="colorControlHighlight">@color/textDanger</item>
</style>
<style name="CustomAutoCompleteTextView" parent="EditTextField">
<item name="android:paddingTop">22dp</item>
<item name="android:paddingStart">10dp</item>
<item name="android:paddingBottom">10dp</item>
<item name="android:paddingEnd">0dp</item>
</style>