16

On an App screen I have a number of EditText views. My app is built using the Material Design (AppCompactActivity, etc).

While showing an EditText field, with a long press I try to select a number of words in the text. This allows me to copy or share that text. Selecting more than 1 word seems not possible.

Since the migration to Material Design I see 2 things:

1 - After a long press there are no selection handles shown. So, on the place of the question marks I expected inverse waterdrops. These are the handles you normally use to change the particular selection.

Question: why are these reverse eyedrops gone? I do see them when selecting text in e.g. a webview.

Yes, I use 'android:textIsSelectable="true"'. Below you see the EditText layout.

enter image description here

2 - The "sharing" option for the selected text is not available. Why?

enter image description here

What is the EditText field?

<EditText
    android:id="@+id/geocache_info_hint"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="15sp"
    android:singleLine="false"
    android:lines="4"
    android:scrollHorizontally="false"
    android:scrollbars="vertical"
    android:layout_marginLeft="5dp"
    android:ellipsize="none"
    android:textIsSelectable="true"
    android:text=""/>

Upon selection of a text (in this case 1 word) what I also see is that an extra bar 'tekstselectie' (=textselection) is put on top of the screen. That's also a difference since Android 4.

enter image description here

** Solution **

In my theme I had a line that caused the problem of not showing any text selection handles:

<item name="android:popupBackground">@color/window_background</item> 

The @color/window_background was chosen as white.

tm1701
  • 7,307
  • 17
  • 79
  • 168
  • Are you building with appcompat-v7 version 23.1.1? – Bob Snyder Jan 01 '16 at 20:22
  • I researched the problem and didn't find anything. Couldn't reproduce on any of my devices. I don't know if using the latest appcompat version would help. – Bob Snyder Jan 04 '16 at 17:08
  • I upgraded everything to 23.1.0. Alas, no change. Why is this working for webview and not for edittext? – tm1701 Jan 05 '16 at 18:45
  • Can you try adding to edittext android:imeOptions="actionSend" ? Also, what is your theme parent? – aelimill Jan 06 '16 at 19:06
  • Adding the imeOptions doesn't help. The theme parent is: – tm1701 Jan 06 '16 at 19:21

2 Answers2

6

Upd2:

Also, as tjm1706 figured out, it's important to carefully review the Theme property. In this case, the key was to remove <item name="android:popupBackground">@color/window_background</item>

Upd1:

  1. To avoid this "double-toolbar" on editing, add this to your Theme's style:

    <item name="windowActionModeOverlay">true</item>
    <item name="actionModeBackground">@drawable/myapp_action_mode_background</item>
    

    taken from here

  2. To add Share (or any other button) - you need to set on your EditText setCustomSelectionActionModeCallback:

    Check out this question: Custom cut/copy action bar for EditText that shows text selection handles - it contains detailed example.

Original:

Try to remove: android:textIsSelectable="true". It's not possible to type with it. And if you don't need EditText to be editable - probably, simple TextView suits you better.

Without it, your EditText works fine for me:

enter image description here

Community
  • 1
  • 1
Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95
  • Alas, it doesn't help. A difference with your demo is that an extra copy-paste bar is put on top of the screen. – tm1701 Jan 07 '16 at 19:06
  • @tjm1706 does it put extra copy-paste bar even on Android M? (this floating bubble thing with share/copy in the gif is standard in M) – Konstantin Loginov Jan 07 '16 at 19:10
  • I updated the 'question' with what I see now. Sufficient info? – tm1701 Jan 07 '16 at 19:12
  • @tjm1706 ok, now I see - then it's an issue with a way you work with a toolbar. I'll try to repro it and update the answer. (Though, the EditText you posted, doesn't work with android:textIsSelectable="true" at all) – Konstantin Loginov Jan 07 '16 at 19:16
  • @tjm1706 I believe, this is the solution you need: http://stackoverflow.com/questions/28277676/how-to-change-the-text-selection-toolbar-color-which-comes-when-we-copy-a-text – Konstantin Loginov Jan 07 '16 at 19:18
  • Well, I found it ... Thanks to you. You gave the right direction. The extra textselection bar, .... I don't mind. BUT ... when looking in the theme I saw the following line... and removed this line. So, when you add this to your answer, you get the bonus of +50. So, this is wrong. It gives a white background ... not showing the handles. @color/window_background – tm1701 Jan 07 '16 at 19:59
  • @tjm1706 interesting fact, though: it in Android M it works even with `android:popupBackground` (but the drops have square background around) :-) Great, that you've figured it out! – Konstantin Loginov Jan 07 '16 at 20:15
0

Add android:textIsSelectable in xml.