1

I have a problem when selecting the text inside an EditText control inside an AlertDialog.

When I select the text, the text selection toolbar shows up at the top of the screen. The problem is that the toolbar background is white, and the icons displayed in the toolbar are also white. Therefore, the icons are not visible (but they work if you touch them). This is on Android 4.2.2 (API 17).

This is the snippet of code I use to create the AlertDialog that contains the EditText. It is located in the onCreate method of my test project's activity.

EditText et = new EditText(this);
et.setText("Test");
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setView(et).setPositiveButton("Ok", null).setNegativeButton("Cancel", null);
b.create().show();

Here is how the text selection toolbar looks when the text is selected:

Text select

How can I change the color of the toolbar and/or icons so that they will be visible?

Ove
  • 6,227
  • 2
  • 39
  • 68
  • Possible duplicate of [Text selection tools in ActionBar are white on white background after selecting text in Dialog](http://stackoverflow.com/questions/28459898/text-selection-tools-in-actionbar-are-white-on-white-background-after-selecting) – Edward Falk Apr 01 '16 at 21:29

1 Answers1

0

I think you can use:

<item name="actionModeBackground">@drawable/background</item>
<item name="android:actionModeBackground">@drawable/background</item>

in your main theme. I'm not sure you can point at colors rather than at drawable. A quick workaround is defining a shape drawable. To be more precise you could have a drawable/background.xml like:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid
        android:color="@color/color" />
</shape>
natario
  • 24,954
  • 17
  • 88
  • 158
  • I've tried defining a color in my colors.xml file and I've added `@color/myredcolor` in my theme, but it has no effect. I still get the white-on-white images. My theme's parent is `Theme.AppCompat.Light.DarkActionBar` – Ove Jan 19 '15 at 14:43
  • Maybe you should use `android:actionModeBackground` also. Plus, I'm not sure this works with colors. Try defining a shape drawable. – natario Jan 19 '15 at 20:29
  • I tried to use a drawable instead of a color, and I tried putting `android:` in front of `actionModeBackground` and it still does not work. I made a pastebin with the files of my test app: [http://pastebin.com/EzfsrDjq](http://pastebin.com/EzfsrDjq). I am running a JellyBean API17 emulator. – Ove Jan 21 '15 at 17:30
  • `@drawable/background` solved the problem for me; I don't know why it was downvoted. – Edward Falk Apr 01 '16 at 21:46