Is it possible to select text from a TextView(including highlight) ?
It is possible with EditText but i need that to be done using TextView ..
Any help regarding this please ?
Thanks,
Use this:
android:textIsSelectable="true"
as easy as pie ;)
Edit:
setting it in code: textView.setTextIsSelectable(true)
Not sure exactly what you are going for, and this may not be exactly what you want, but you can register it for a ContextMenu and then use onCreateContextMenu
and the CLIPBOARD_SERVICE
:
private TextView mTextView;
protected final void onCreate(Bundle savedInstanceState) {
...
registerForContextMenu(mTextView);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
TextView textView = (TextView) view;
menu.setHeaderTitle(textView.getText()).add(0, 0, 0, R.string.menu_copy_to_clipboard);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText(mTextView.getText());
return true;
}
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