【发布时间】:2021-03-29 10:41:39
【问题描述】:
我使用TextInputLayout 和AutoCompleteTextView 在下拉视图中显示项目列表。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilCategoriesDropdown"
style="@style/DropdownTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:endIconMode="dropdown_menu"
app:hintEnabled="false">
<AutoCompleteTextView
android:id="@+id/actvCategoriesDropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/MyTextStyle"
android:editable="false"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
风格
<style name="DropdownTextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu">
<item name="boxStrokeColor">@color/color_dropdown_box_stroke</item> // P.s. not sure what what states should be specified in color selector
...
</style>
颜色状态列表
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:color="@color/carbon_green_500" android:state_focused="true"/>
<item android:color="@color/carbon_red_600" android:state_focused="false" />
<item android:color="@color/carbon_red_600" android:state_pressed="false"/>
<item android:color="@color/carbon_red_600"/>
</selector>
问题:在下拉列表显示/隐藏的状态下,如何在TextInputLayout 视图周围显示不同颜色的笔划。 例如:绿色显示下拉列表时的笔划,隐藏时显示红色。我尝试了不同状态的颜色选择器的不同组合,但无法达到我想要的结果。
【问题讨论】:
标签: android material-design autocompletetextview material-components-android android-textinputlayout