12

Where does the green color comes from? I've tried changing the accentColor attribute, which works in other parts of the app, but not here.

editText Colors Screenshot from app in Lollipop.

How can I change the colors of:

  • the text handle drawables? how to tint them?
  • the select-all-background color?

And maybe some tips for the future... How did you find out? I've been coming across all these confusing color/styling problems. Is there some kind of list somewhere that tells me, which default color or attribute that I need to overwrite for a certain component?

Jonik
  • 80,077
  • 70
  • 264
  • 372
Lokkio
  • 1,703
  • 2
  • 16
  • 19
  • Possible duplicate of [How to change color / appearance of EditText select handle / anchor?](https://stackoverflow.com/questions/15133926/how-to-change-color-appearance-of-edittext-select-handle-anchor) – Vadim Kotov Mar 13 '19 at 15:55

2 Answers2

10

For changing the handle color you can do as specified here you do it using style as

<style name="MyCustomTheme" parent="@style/MyNotSoCustomTheme">
        <item name="android:textSelectHandle">@drawable/text_select_handle_middle</item>
        <item name="android:textSelectHandleLeft">@drawable/text_select_handle_left</item>
        <item name="android:textSelectHandleRight">@drawable/text_select_handle_right</item>
</style>

For doing it programmatically check same question another reply here which is done using reflection

try {
    final Field fEditor = TextView.class.getDeclaredField("mEditor");
    fEditor.setAccessible(true);
    final Object editor = fEditor.get(editText);

    final Field fSelectHandleLeft = editor.getClass().getDeclaredField("mSelectHandleLeft");
    final Field fSelectHandleRight = editor.getClass().getDeclaredField("mSelectHandleRight");
    final Field fSelectHandleCenter = editor.getClass().getDeclaredField("mSelectHandleCenter");

    fSelectHandleLeft.setAccessible(true);
    fSelectHandleRight.setAccessible(true);
    fSelectHandleCenter.setAccessible(true);

    final Resources res = context.getResources();

    fSelectHandleLeft.set(editor, res.getDrawable(R.drawable.text_select_handle_left));
    fSelectHandleRight.set(editor, res.getDrawable(R.drawable.text_select_handle_right));
    fSelectHandleCenter.set(editor, res.getDrawable(R.drawable.text_select_handle_middle));
} catch (final Exception ignored) {
}

For changing the selected text color you can set textColorHighlight in xml as

android:textColorHighlight="#ff0000"

through style you can do as

<item name="android:textColorHighlight">@color/m_highlight_blue</item>
Community
  • 1
  • 1
Rajen Raiyarela
  • 5,526
  • 4
  • 21
  • 41
  • 1
    thanks for helping, I liked both answers, but yours was more about the text handlers. I guess there is no way of just tinting them? yeah maybe get the drawable first and then tint it... – Lokkio Apr 23 '15 at 08:47
4

Make changes to your styles.xml as follows

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorControlHighlight">@color/accent_translucent</item>
    <item name="android:colorControlHighlight">@color/accent_translucent</item>
    <item name="colorAccent">@color/accent</item>
    <item name="selectableItemBackground">@drawable/selectable_item_background</item>
    <item name="android:selectableItemBackground">@drawable/selectable_item_background</item>

</style>

<color name="primary">#00BCD4</color>
<color name="primary_dark">#0097A7</color>
<color name="accent">#FFEB3B</color>
<color name="accent_translucent">#80FFEB3B</color>
<color name="accent_bright">#FFF493</color>

Or you can add a XML attribute to your EditText

android:textColorHighlight="@color/accent_translucent"

Hope it solves your problem.

ch3tanz
  • 3,070
  • 3
  • 16
  • 24
  • I also like your answer, because it sets the colors over the whole app. Just one weird thing I havent figured out yet. One of my edittexts does not take over the theme and the other edittext does... Do you maybe know, of a condition when edittexts do not take over the styling? maybe wrong inflating issue? – Lokkio Apr 23 '15 at 08:50
  • Thanks @Lokkio . No, I haven't faced such issues. It may be due to inflating issues. – ch3tanz Apr 23 '15 at 08:56