You can get the selected word using the getSelectionStart()
and getSelectionEnd()
methods:
EditText etx=(EditText)findViewById(R.id.editext); int startSelection=etx.getSelectionStart(); int endSelection=etx.getSelectionEnd(); String selectedText = etx.getText().substring(startSelection, endSelection);
You can then apply your specific formatting using this selected substring in the full line after you go to SpannableStringBuilder when you press the / button in another event:
Code for formatting text:
int startSelection=etx.getSelectionStart(); int endSelection=etx.getSelectionEnd(); final SpannableStringBuilder sb = new SpannableStringBuilder(etx.getText().toString()); final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);
Link
source share