Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Text Selectable - select part of a text

How can I make a TextView selectable in API <= 11 ? I search a lot and found that i could use Editext as a TextView, but this away don't looks good anyway, and I need to send the part selected of a text to a new Activity, Someone could help me with this ?

A example of what i'm searching for is the Onlongclick pressed in app OperaMini. After a long click he opens a cursor for the user select that part of the text that him Need and a ContextMenu for that selected part.

Thank's.

enter image description here

I need to make something like this Print, when longclinck, make appears the selectors of text(the blue tips on the print) and show the part selected.

like image 782
FpontoDesenv Avatar asked Aug 25 '13 05:08

FpontoDesenv


People also ask

How do you set the part of the text view is clickable in android?

This example demonstrates how do I set the part of the Android textView as clickable. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is GetSelectionStart?

GetSelectionStart(ICharSequence) Return the offset of the selection anchor or cursor, or -1 if there is no selection or cursor. GetSelectionStart(String) Return the offset of the selection anchor or cursor, or -1 if there is no selection or cursor.

How to Make text selectable in Android Studio?

To make text selectable in android using XML, you have to add a attribute in TextView called android:textIsSelectable="true". You can also do same thing using java code too and you have to add textView. setTextIsSelectable(true); in your java code.

What is selection in android?

↳ android.text.Selection. Utility class for manipulating cursors and selections in CharSequences. A cursor is a selection where the start and end are at the same offset.


1 Answers

You either in xml make it selectable

        android:textIsSelectable="true"

or making your textview clickable by assigning it a Onclicklistener

  TextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
        clipboard.setText(TextView.getText());
        }
    });
like image 145
Ahmed Ekri Avatar answered Nov 03 '22 01:11

Ahmed Ekri