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>"));