Can't change cursor and bubble color for Material TextInputEditText

谁说我不能喝 提交于 2020-06-25 06:53:05

问题


I want to change Material TextInputEditText's bubble and cursor color. I tried colorAccent, android:textCursorDrawable these are not working correctly.

Files in here

You can see it in this image


回答1:


You have to use following attributes:

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

To know more about : Setting up a Material Components theme for Android




回答2:


The material attribute color colorControlActivated do the magic. You have to create a style for your TextInputLayout.

e.g:

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

Then you have to apply this style in the theme attribute of control:

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


来源:https://stackoverflow.com/questions/54487356/cant-change-cursor-and-bubble-color-for-material-textinputedittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!