如何更改textinputlayout内textinputedittext中的光标颜色

问题描述 投票:0回答:2

enter image description here

如何更改textinputedittext的光标颜色。

我使用了textcursordrawable,但它不起作用。 预先感谢

android xml material-design android-textinputlayout android-textinputedittext
2个回答
3
投票

如果您只想更改光标颜色,可以使用:

<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>


0
投票

从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"
...
© www.soinside.com 2019 - 2024. All rights reserved.