How can I change the Edittext selection and pointer color?

Asked

Viewed 574 times

2

I want to change the color of seleção of the text in a EditText and also change the color of bolinha (name is pointer if I’m not mistaken) by java.

It has to be the same as the image that follows only with another color.

inserir a descrição da imagem aqui

2 answers

3


I think that it is not possible to change, dynamically (after Edittext has been created), via java.

Via XML, create a style:

<style name="SelectionColor">
    <item name="colorControlActivated">#00ff00</item>
    <item name="android:textColorHighlight">#00ff00</item>
</style>

apply it to Edittext using

android:theme="@style/SelectionColor"

Notes:

  • The example uses the green color.
  • Cursor color will also be changed.

1

You can change these things in the values/Colors.xml file

<resources>
    <color name="primary">#3F51B5</color>
    <color name="primary_dark">#303F9F</color>
    <color name="primary_light">#C5CAE9</color>
    <color name="accent">#00BCD4</color>
    <color name="primary_text">#212121</color>
    <color name="secondary_text">#727272</color>
    <color name="icons">#FFFFFF</color>
    <color name="divider">#B6B6B6</color>
</resources>

More information:
https://developer.android.com/samples/DirectShare/res/values/colors.html
https://developer.android.com/training/material/theme.html

You can create style:

<style name="green">
        <item name="main_background">@drawable/background_green</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="button_light">@color/button_light</item>
</style>

And set in code:

activity.setTheme(R.style.green);

More information:
https://developer.android.com/guide/topics/ui/look-and-feel/themes.html

  • You can do it for the java ?

  • I edited the question with this answer.

  • I think that would be the best answer if there were more details

Browser other questions tagged

You are not signed in. Login or sign up in order to post.