Search code examples
androidandroid-edittextandroid-themeandroid-styles

EditText uses color Accent for this pointer in the photo provided


I found that EditText uses a default color Accent for the pointer , so how can i change the color of it ?

enter image description here

On my EditText, if i insert android:theme= @style/mytheme, it will work but when i use style = "@style/mytheme", it won't work.

The problem is that when i use android:theme= @style/mytheme EditText hint disappears .

How can i change the color of it using custom style ?

Here is my code:

 <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="@string/cap"
        android:background="@drawable/input_shape"
        android:drawableStart="@drawable/search"
        android:drawableLeft="@drawable/search"
        android:inputType="number"
        android:id="@+id/capInput"
        style="@style/MyEditText"/>

and the custom style :

    <style name="MyEditText" parent="@android:style/Widget.EditText">
    <item name="colorAccent">@color/notification_material_background_media_default_color</item>
</style>

Thanks in advance !


Solution

  • EditText (Copy-Paste) Bouble uses colorAccent of you app theme for its color, you can change colorAccent on your appTheme, or you can create a new style and set it as EditText theme

    <style name="CustomEditText" >
        <item name="colorAccent">@color/your_favourite_color</item>
    </style>
    

    and set it to your EditText:

    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Your Hint"
            android:theme="@style/CustomEditText"
           />
    

    if you want to use other attributes of you appTheme you can just set it as parent style and just change its colorAccent

    <style name="CustomEditText" parent="AppTheme">
        <item name="colorAccent">@color/your_favourite_color</item>
    </style>