I want to set span color on my EditText. It works fine when str
is a single line or at the end of multi lined str
. But if it is at the end of any of these inside lines, span does not color this part at the end of the line. How to solve that?
private void changeAddEtBackgroundColor(EditText et, int startIndex, String str) {
Spannable raw = new SpannableString(et.getText());
raw.setSpan(new BackgroundColorSpan(Color.GREEN), startIndex, startIndex + str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
et.getEditableText().replace(0, et.length(), raw);
et.setSelection(etDescPosition);
}
here is also this view in layout in case it is needed:
<EditText
android:id="@+id/et_note_desc_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="top|start"
android:hint="@string/enter_desc"
android:maxLength="9000"
android:textColor="?attr/myTextColor"
android:textColorHint="?attr/myHintTextColor"
android:textSize="18sp" />