我试图让 AutoCompleteTextView 看起来像一个 material Edittext
I am trying to make AutoCompleteTextView look like a material Edittext
我正在尝试使 AutoCompleteTextView
看起来像这张图片 https://ibb.co/ZJxmgK5 但无法做到这一点。轮廓框在结果中不可见
下面是我当前的代码。早些时候我尝试在 TextInputLayout
中添加一个 EditText
但现在我想在其中添加自动完成。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout_holiday_destination"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/lbl_destination_big">
<AutoCompleteTextView
android:id="@+id/edittext_holiday_destination"
style="@style/Base.Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="10"
android:background="@android:color/transparent"
android:hint="@string/lbl_destination"
android:layout_marginLeft="@dimen/margin8"
android:singleLine="true"
android:lines="1"
android:textSize="25sp"
android:nextFocusDown="@+id/txv_holiday_num_of_nights"
android:imeOptions="actionNext"
android:textCursorDrawable="@drawable/edittext_cursor_drawable"/>
/>
</com.google.android.material.textfield.TextInputLayout>
预期结果是上面给出URL的图像。
如果您想将 TextInputLayout
与 AutoCompleteTextView
结合使用,您应该将此样式用于 TextInputLayout
Widget.MaterialComponents.TextInputLayout.*.ExposedDropdownMenu
.
你的情况:
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
使用类似于:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/name_text_input"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="HINT TEXT">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"/>
</com.google.android.material.textfield.TextInputLayout>
同时检查 doc:
Note: When using an outlined text field with an EditText
child that is not a TextInputEditText
, make sure to set the EditText's android:background
to @null
. This allows TextInputLayout
to set an outline background on the EditText
.
如果您想避免下拉图标,只需使用 app:endIconMode
属性即可。
<com.google.android.material.textfield.TextInputLayout
app:endIconMode="none"
...>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout_holiday_destination"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/edittext_holiday_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Destination"
android:layout_weight="10"
android:singleLine="true"
android:lines="1"
android:textSize="25sp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
tools:text="Hello" />
/>
</com.google.android.material.textfield.TextInputLayout>
这行得通。问题出在您设置为 AutoCompleteTextView
.
的背景颜色
下面的代码解决了问题:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout_holiday_destination"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/lbl_destination_big">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/edittext_holiday_destination"
style="@style/Widget.MaterialComponents.AutoCompleteTextView.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:lines="1"
android:nextFocusDown="@+id/txv_holiday_num_of_nights"
android:imeOptions="actionNext"
android:textCursorDrawable="@drawable/edittext_cursor_drawable"
/>
</com.google.android.material.textfield.TextInputLayout>
finally my answer is this
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/uomLay"
android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="@id/quantity_lay"
app:layout_constraintStart_toStartOf="@id/start2"
app:layout_constraintEnd_toEndOf="@id/end2"
style="@style/OutlineBoxDropDown"
app:endIconDrawable="@drawable/ic_path_16692"
app:shapeAppearance="@style/Rounded"
app:hintTextAppearance="@style/hintTextAppearence"
android:layout_marginTop="@dimen/_13sdp"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/uom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/graphikregular"
android:hint="UOM"
style="@style/Widget.MaterialComponents.AutoCompleteTextView.OutlinedBox"
android:background="@null"
android:paddingVertical="@dimen/_7sdp"
android:textColor="@color/desc_color"
android:textSize="@dimen/_11ssp"
tools:text="kg" />
</com.google.android.material.textfield.TextInputLayout>
我正在尝试使 AutoCompleteTextView
看起来像这张图片 https://ibb.co/ZJxmgK5 但无法做到这一点。轮廓框在结果中不可见
下面是我当前的代码。早些时候我尝试在 TextInputLayout
中添加一个 EditText
但现在我想在其中添加自动完成。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout_holiday_destination"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/lbl_destination_big">
<AutoCompleteTextView
android:id="@+id/edittext_holiday_destination"
style="@style/Base.Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="10"
android:background="@android:color/transparent"
android:hint="@string/lbl_destination"
android:layout_marginLeft="@dimen/margin8"
android:singleLine="true"
android:lines="1"
android:textSize="25sp"
android:nextFocusDown="@+id/txv_holiday_num_of_nights"
android:imeOptions="actionNext"
android:textCursorDrawable="@drawable/edittext_cursor_drawable"/>
/>
</com.google.android.material.textfield.TextInputLayout>
预期结果是上面给出URL的图像。
如果您想将 TextInputLayout
与 AutoCompleteTextView
结合使用,您应该将此样式用于 TextInputLayout
Widget.MaterialComponents.TextInputLayout.*.ExposedDropdownMenu
.
你的情况:
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
使用类似于:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/name_text_input"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="HINT TEXT">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"/>
</com.google.android.material.textfield.TextInputLayout>
同时检查 doc:
Note: When using an outlined text field with an
EditText
child that is not aTextInputEditText
, make sure to set the EditText'sandroid:background
to@null
. This allowsTextInputLayout
to set an outline background on theEditText
.
如果您想避免下拉图标,只需使用 app:endIconMode
属性即可。
<com.google.android.material.textfield.TextInputLayout
app:endIconMode="none"
...>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout_holiday_destination"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/edittext_holiday_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Destination"
android:layout_weight="10"
android:singleLine="true"
android:lines="1"
android:textSize="25sp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
tools:text="Hello" />
/>
</com.google.android.material.textfield.TextInputLayout>
这行得通。问题出在您设置为 AutoCompleteTextView
.
下面的代码解决了问题:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout_holiday_destination"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/lbl_destination_big">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/edittext_holiday_destination"
style="@style/Widget.MaterialComponents.AutoCompleteTextView.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:lines="1"
android:nextFocusDown="@+id/txv_holiday_num_of_nights"
android:imeOptions="actionNext"
android:textCursorDrawable="@drawable/edittext_cursor_drawable"
/>
</com.google.android.material.textfield.TextInputLayout>
finally my answer is this
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/uomLay"
android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="@id/quantity_lay"
app:layout_constraintStart_toStartOf="@id/start2"
app:layout_constraintEnd_toEndOf="@id/end2"
style="@style/OutlineBoxDropDown"
app:endIconDrawable="@drawable/ic_path_16692"
app:shapeAppearance="@style/Rounded"
app:hintTextAppearance="@style/hintTextAppearence"
android:layout_marginTop="@dimen/_13sdp"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/uom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/graphikregular"
android:hint="UOM"
style="@style/Widget.MaterialComponents.AutoCompleteTextView.OutlinedBox"
android:background="@null"
android:paddingVertical="@dimen/_7sdp"
android:textColor="@color/desc_color"
android:textSize="@dimen/_11ssp"
tools:text="kg" />
</com.google.android.material.textfield.TextInputLayout>