如何更改textinputedittext的光标颜色。
我使用了textcursordrawable,但它不起作用。 预先感谢
如果您只想更改光标颜色,可以使用:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:theme="@style/ThemeOverlay.AppTheme.TextInputEditText.Outlined"
....>
与:
<style name="ThemeOverlay.AppTheme.TextInputEditText.Outlined" parent="">
<item name="colorControlActivated">@color/...</item>
</style>
如果您想更改光标颜色,还想更改框、标签..
<style name="ThemeOverlay.AppTheme.TextInputEditText.Outlined" parent="">
<item name="colorPrimary">@color/...</item>
</style>
从material-components-android库1.10.0版本开始,可以直接设置光标颜色。
只需将属性添加到您的 TextInputLayout 视图即可:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorErrorColor="@color/error_color"
app:cursorColor="@color/accent_color"
...