'Change Material TextInputLayout stroke color in dropdown state
I'm using TextInputLayout with AutoCompleteTextView to show a list of items in a dropdown view.
<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
<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>
Color state list
<?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>
Question: How can I achieve having different colors of the stroke around the TextInputLayout view in states where the dropdown list is shown/hidden. ex: green color of the stroke when the dropdown list is show and red when it's hidden. I've tried different combinations of color selectors with different states but couldn't achieve the result I'm looking for.
Solution 1:[1]
You need to put app:endIconTint
<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:endIconTint="@color/white"
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zamokuhle Shozi |
