【问题标题】:Change Material TextInputLayout stroke color in dropdown state在下拉状态下更改 Material TextInputLayout 笔触颜色
【发布时间】:2021-03-29 10:41:39
【问题描述】:

我使用TextInputLayoutAutoCompleteTextView 在下拉视图中显示项目列表。

 <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


    【解决方案1】:

    你需要把 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>
    

    【讨论】:

      猜你喜欢
      • 2020-12-16
      • 2019-08-22
      • 2018-03-21
      • 1970-01-01
      • 2017-04-08
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多