Setting textIsSelectable in a TextView with selection tent ellipsis adds an ellipse

The screen in my application will potentially display really long lines in a TextView . For this scenario, I have android:ellipsize="marquee" , so the text will be highlighted through the TextView.

However, I decided that I also want this text to be selectable ( android:textIsSelectable="true" ). In most cases, this is not a problem. The text is smaller than the TextView, and the user can simply select it. However, if I have a textIsSelectable attribute, and if the text is larger than the TextView, the text will perceive an ellipse instead of a full line. It will still highlight , but no longer displays the full text. He cuts it off and displays an ellipse.

  <TextView android:layout_width="wrap_content" android:layout_height="?android:attr/listPreferredItemHeightSmall" android:ellipsize="marquee" android:focusable="true" android:gravity="center_vertical" android:singleLine="true" android:textIsSelectable="true"> 

Is there a way to select the text and save the entire line in the selection area (without an ellipse)?

+7
android android-textview
source share
1 answer

Unable to verify that this is a mistake.

 <TextView android:layout_width="wrap_content" android:layout_height="?android:attr/listPreferredItemHeightSmall" android:ellipsize="start" android:focusable="true" android:gravity="center_vertical" android:singleLine="true" android:textIsSelectable="true"/> 

Please note that we set android:ellipsize="start" in xml - more on this later.

 mTextView = (TextView) findViewById(R.id.tv); mTextView.post(new Runnable() { @Override public void run() { mTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE); mTextView.setSelected(true); } }); 

setEllipsize(TruncateAt) checks if the current ellipsize value ellipsize the specified one. To get around this, we supply android:ellipsize="start" in xml. Thus, TextView has no problem accepting TextUtils.TruncateAt.MARQUEE later.

Now, although this works, I suggest you not do this. You can understand why - as soon as you try this code. It seems that textIsSelectable not supposed to be used with marquee - selection descriptors do not move along with the text.

All in all, it looks extremely sketchy.

+1
source share

All Articles