1

I need to set the complete string as set text and need to format specific substring using the following way:

int startSelection = binding.editText.getSelectionStart();
int endSelection = binding.editText.getSelectionEnd();
String selectedText = binding.editText.getText().toString().substring(startSelection, endSelection);
binding.editText.setText(Html.fromHtml("<i>"+selectedText+"</i>"));
Akhil Dad
  • 1,804
  • 22
  • 35
nmnm
  • 11
  • 3
  • try to use style span on the string, you can use refer below example https://stackoverflow.com/questions/4623508/how-to-set-the-font-style-to-bold-italic-and-underlined-in-an-android-textview – Akhil Dad Sep 02 '22 at 17:59
  • Also you are only selecting subString you need to set the complete string again with formatting – Akhil Dad Sep 02 '22 at 18:03

0 Answers0