【问题标题】:Changing the arrow color material ExposedDropdownMenu / TextInputLayout更改箭头颜色材质 ExposedDropdownMenu / TextInputLayout
【发布时间】:2020-08-15 18:11:38
【问题描述】:
我想将箭头颜色更改为白色。怎么做?这是我的代码
<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>
我希望它很清楚。提前致谢。
【问题讨论】:
标签:
android
material-design
android-textinputlayout
material-components-android
material-components
【解决方案1】:
如果你想改变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>
【解决方案2】:
使用简单地将 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>
【解决方案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>