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.
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.
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.
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.
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.
↳ 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.
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());
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With