Android select and highlight text in edittext
I would like to do an app which has an EditText or TextView that can be selected upon click and highlight the selected text. How can I do that? I tried overriding onClick method on my EditText but seems not working. Here's what I've tried so far: etx.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { int startSelection = etx.getSelectionStart(); int endSelection = etx.getSelectionEnd(); //String selectedText = etx.getText().toString().substring(startSelection, endSelection); Spannable spannable=new SpannableString(etx.getText().toString());