Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - edittext - no textselection handles are shown and no sharing option

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.

like image 362
tm1701 Avatar asked Jan 01 '16 11:01

tm1701


1 Answers

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

like image 149
Konstantin Loginov Avatar answered Nov 04 '22 05:11

Konstantin Loginov