9

I've just noticed that all my EditText fields in my app do not show the selection anchors correctly. For example:

Image with no selection anchors

However, what I expect is the correct anchors to appear such as:

Image with selection anchors

A typical example of an affected EditText in my app:

<EditText
    android:id="@+id/text_message"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/button_send"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:inputType="text|textShortMessage"
    android:layout_marginRight="4dp"
    android:hint="@string/hint_chat_send" />

Also notice that the "paste" hover view has a strange white border around it in my app, but in other apps it is completely transparent.

I suspect some kind of theme issue, since it affects multiple screens in my app, but I cannot find info on which attributes may cause this.

UPDATE

So, I've spent a few way too many hours debugging the EditText, TextView, and Editor framework classes to no avail. Everything appears to be functioning as expected.

I created a new blank Activity in the same application with the following layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <EditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:hint="test" />

</RelativeLayout>

In my other screens, I am using the AppCompat library and it's related themes, but in this Activity I overrode the theme and the Activity to be a stock Android Activity with the built-in Material theme:

public class TestActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

    setTheme(android.R.style.Theme_Material_Light_NoActionBar);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_test);
}
...

It's my understanding calling setTheme in this manner should override any possible customizations from my app styles.xml. Still, I see this:

Markers not shown on simulator

Kind of at a loss here still...

3
  • 1
    I came across this issue few times in different apps and confused that nobody notified this anywhere. I tried to reproduce it but was failed. So if you will find some kind of reason, please, make a bug report.
    – Nolan
    Commented Jul 16, 2015 at 22:29
  • Can you post your theme?
    – Paul Burke
    Commented Jul 21, 2015 at 23:18
  • Updated with some more details, including stripping away my current theme... Commented Jul 24, 2015 at 18:37

2 Answers 2

1

The solution is to remove android:popupBackground which I had set in my theme:

<!-- This will break the text selection popup -->
<item name="android:popupBackground">@color/not_quite_white</item>

I had this set to try and theme all the Spinner dropdown backgrounds to the same color. For whatever reason, it interferes with the text selection popup. Furthermore, calling Activity.setTheme apparently did not override this property, leading to some confusion.

0
+50

The class responsible for drawing the handles is the SelectionModifierCursorController Which lives in the Editor class. For it not to display the cursors (left and right selection cursor) hide must have been called on the instance. This is done for instance when the touch mode for the view changes.

http://androidxref.com/5.1.1_r6/xref/frameworks/base/core/java/android/widget/Editor.java#3976

Or if the TextViews (EditTexts are basically text views) textCanBeSelected returns false: http://androidxref.com/5.1.1_r6/xref/frameworks/base/core/java/android/widget/Editor.java#479

Or a few other situations, but let's start here for the investigation.

To make sure nothing is off with the touch mode could you call isInTouchMode on one EditText where it works and one where it does not?

To make sure the textCanBeSelected is correct, could you call that method on one EditText where it works and one where it does not.

If all is well with both of these we will have to continue digging ;)

4
  • Thanks for looking in to that. See my updates, but basically isInTouchMode was returning true and no amount of setTextSelectable had any effect... Commented Jul 24, 2015 at 18:36
  • That is a shame, do you have the same behavior across multiple android versions, primarily, Lollipop -> Kitkat? Commented Jul 24, 2015 at 20:57
  • I just finally found the solution. It was a rogue attribute set in one of my themes. I came upon the idea indirectly from looking at the source you linked, so I awarded you the bounty. Commented Jul 24, 2015 at 21:36
  • Great, I'm glad you found the answer! If you have a link to the piece of code I'd love to take a look at it. Maybe there is an easy solution that can be upstreamed. Commented Jul 24, 2015 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.