I want to display an icon within text inside an EditText. I am using the following code snippet:
Html.ImageGetter imageGetter;
Spanned cs;
imageGetter = new Html.ImageGetter() {
public Drawable getDrawable(String source) {
Drawable d = getResources().getDrawable(R.drawable.icon);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.icon) + "'/>", imageGetter, null);
It was taken from this answer: https://stackoverflow.com/a/7200218/930835
then it's used this way:
editable.clear();
editable.insert(0,(leftPartString+" "+cs+" "+rightPartstring));
editText.setText(editable);
R.drawable.icon corresponds to an xml file with a svg inside:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/icon"
>
<svg code here.../>
</svg>
</selector>
I adapted it from other drawable files found in the directory.
When the application runs I get a strange symbol instead of the desired icon, that is a box with "obj" text inside.
How to get the right visualization?