更改箭头颜色材质ExposedDropdownMenu / TextInputLayout

时间:2020-05-01 08:48:02

标签: android material-design android-textinputlayout material-components-android material-components

I want to change the arrow color to white. how to do it? here's my code

我想将箭头颜色更改为白色。怎么做?这是我的代码

<com.google.android.material.textfield.TextInputLayout
    style="@style/ExposedDropdownMenu"
    android:hint="Select"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <AutoCompleteTextView
        android:focusable="false"
        android:textSize="17sp"
        android:padding="15dp"
        android:textColorHint="@color/white"
        android:textColor="@color/white"
        android:id="@+id/actv_pool"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:ignore="LabelFor" />

</com.google.android.material.textfield.TextInputLayout>

这是我的风格:

<style name="ExposedDropdownMenu" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
    <item name="boxStrokeColor">#fff</item>
    <item name="boxStrokeWidth">1dp</item>
    <item name="android:textColorHint">#fff</item>
</style>

我希望这很清楚。预先感谢。

3 个答案:

答案 0 :(得分:3)

您可以在布局中使用 app:endIconTint 属性:

 <com.google.android.material.textfield.TextInputLayout
            ...
            app:endIconTint="@color/my_selector_color">

或者您可以使用自定义样式:

 <com.google.android.material.textfield.TextInputLayout
    style="@style/ExposedDropdownMenu"
    ...>

具有:

  <style  name="name="ExposedDropdownMenu" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
    <item name="endIconTint">@color/my_selector_color</item>
  </style>

答案 1 :(得分:0)

简单地将 endIconTint 属性添加到 TextInputLayout 使用

app:endIconTint="@color/primaryDarkColor"

哪里

@color/primaryDarkColor

是您想要的颜色

以下带有完整 XML 代码的示例


        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/til_paying_bank"
            style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/til_withdrawal_date"
            android:layout_centerHorizontal="true"
            android:padding="5dp"
            app:endIconTint="@color/primaryDarkColor">

            <AutoCompleteTextView
                android:id="@+id/actv_paying_bank"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/paying_bank"
                android:dropDownSelector="@color/primaryLightColor"
                />

        </com.google.android.material.textfield.TextInputLayout>

答案 2 :(得分:0)

如果你想改变drawable,不仅仅是颜色,你可以设置endIconDrawable。对于 drawable 放置一个选择器 xml,如下所示:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">

      <item android:drawable="@drawable/ic_page_up" android:state_checked="true"/>
      <item android:drawable="@drawable/ic_page_down"/>
    </selector>