Ability to draw in string resources

I want to show AlertDialogthat shows my message with a string and icons together.

Can I embed icons / images / drawings in a string resource? Is there a way to show drawables with a string AlertDialog.

EDIT
If this is unclear, the drawings should be inside the line. for example, "click the [image icon] icon, and then click" ... "

+4
source share
3 answers

The class AlertDialog.Builderhas a method setIcon(int iconRes)or setIcon(Drawable icon)that you can use to do this.

EDIT:

, ImageSpan:

String src = "Here an icon: @ isn't it nice?";
SpannableString str = new SpannableString(src);
int index = str.indexOf("@");
str.setSpan(new ImageSpan(getResources().getDrawable(R.drawable.my_icon), index, index + 1, ImageSpan.ALIGN_BASELINE));

AlertDialog.Builder x = new AlertDialog.Builder(myContext);
x.setMessage(str);
+2
    SpannableString spannableString = new SpannableString("@");
    Drawable d = getResources().getDrawable(R.drawable.your_drawable);
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
    spannableString.setSpan(span, spannableString.toString().indexOf("@"),  spannableString.toString().indexOf("@")+1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    yourTextView.setText(spannableString);
+8

You can use a custom view or custom title using ImageView or TextView containing composite drawings.

0
source

All Articles