无法更改 Material TextInputEditText 的光标和气泡颜色

我想更改 Material TextInputEditText 的气泡和光标颜色。我试过 colorAccent,android:textCursorDrawable 这些都不能正常工作。


http://img2.mukewang.com/629abbd60001384301650063.jpg

茅侃侃
浏览 188回答 3
3回答

慕桂英546537

材质属性颜色colorControlActivated具有魔力。您必须为 TextInputLayout 创建样式。例如:<style name="TextInputLayoutAppearance" parent="Widget.Design.TextInputLayout">&nbsp; &nbsp; <item name="colorControlNormal">@color/white</item>&nbsp; &nbsp; <item name="colorControlActivated">@color/red</item>&nbsp; &nbsp; <item name="colorControlHighlight">@color/blue</item></style>然后你必须在控件的主题属性中应用这个样式:&nbsp;<com.google.android.material.textfield.TextInputLayout&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/lblObservaciones"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:theme="@style/TextInputLayoutAppearance"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app:boxStrokeColor="@color/blue"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app:hintTextAppearance="@style/TextAppearance.AppCompat.Medium"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app:hintTextColor="@color/blue">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <com.google.android.material.textfield.TextInputEditText&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/comments"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="100dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:gravity="top"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:inputType="textMultiLine"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:maxLength="200" /></com.google.android.material.textfield.TextInputLayout>

慕容森

只需在应用程序主题(日/夜)中应用colorControlActivated,所有 Material TextInputEditField 将具有更改的光标颜色<item&nbsp;name="android:colorControlActivated">@color/green</item>

慕盖茨4494581

您必须使用以下属性:<style&nbsp;name="AppTheme"&nbsp;parent="Theme.MaterialComponents.Light"> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorPrimary">#212121</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorPrimaryVariant">#000000</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorOnPrimary">#FFFFFF</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorSecondary">#2962FF</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorSecondaryVariant">#0039CB</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorOnSecondary">#FFFFFF</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorError">#F44336</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorOnError">#FFFFFF</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorSurface">#FFFFFF</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorOnSurface">#212121</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="android:colorBackground">@color/background</item> &nbsp;&nbsp;&nbsp;&nbsp;<item&nbsp;name="colorOnBackground">#212121</item></style><color&nbsp;name="background">#FAFAFA</color>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java