答案 0 :(得分:3)
只需在应用主题(白天/黑夜)中应用 colorControlActivated,所有 Material TextInputEditField 都会改变光标颜色
<item name="android:colorControlActivated">@color/green</item>
答案 1 :(得分:1)
您必须使用以下属性:
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryVariant">#000000</item>
<item name="colorOnPrimary">#FFFFFF</item>
<item name="colorSecondary">#2962FF</item>
<item name="colorSecondaryVariant">#0039CB</item>
<item name="colorOnSecondary">#FFFFFF</item>
<item name="colorError">#F44336</item>
<item name="colorOnError">#FFFFFF</item>
<item name="colorSurface">#FFFFFF</item>
<item name="colorOnSurface">#212121</item>
<item name="android:colorBackground">@color/background</item>
<item name="colorOnBackground">#212121</item>
</style>
<color name="background">#FAFAFA</color>
答案 2 :(得分:1)
材质属性颜色 colorControlActivated 发挥了神奇作用。您必须为TextInputLayout创建样式。
例如:
<style name="TextInputLayoutAppearance" parent="Widget.Design.TextInputLayout">
<item name="colorControlNormal">@color/white</item>
<item name="colorControlActivated">@color/red</item>
<item name="colorControlHighlight">@color/blue</item>
</style>
然后,您必须在控件的主题属性中应用此样式:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/lblObservaciones"
android:theme="@style/TextInputLayoutAppearance"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxStrokeColor="@color/blue"
app:hintTextAppearance="@style/TextAppearance.AppCompat.Medium"
app:hintTextColor="@color/blue">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/comments"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="top"
android:inputType="textMultiLine"
android:maxLength="200" />
</com.google.android.material.textfield.TextInputLayout>