Textinside Image or Icon : Spannable Text inside Image

December 28, 2017 , 0 Comments

Multiple Way to Add this ICON But It's Depend which item where to use:

Icon add inside the Text Item Like : hello this is image add inside text.

1St way :

HOW TO ADD this ICON :
SpannableString ss = new SpannableString(getString(R.string.<your_text>));
Drawable d = getResources().getDrawable(R.drawable.ic_search); //drawable image
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
ss.setSpan(span, <(in this case)start StringCounter>11,<End string counter> 13, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
//<Splace the icon in which place>
text_icon_1.setText(ss);

2nd  way : ADD UNICODE ICON : How to use
<TextView
android:id="@+id/text_icon_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello this is \u2315 image add inside text." />

NOTE: many times what ever icon we need it's not availabe in unicode system. so better way 1st step is good. hello this is \u2315 image add inside text. //only JAVA/Android working

3nd  way : ADD UNICODE ICON : How to use


TextView text=findViewById(R.id.text);
if (Build.VERSION.SDK_INT >= 24) {
text.setText(Html.fromHtml("hello this is 🔍", Html.FROM_HTML_MODE_LEGACY));
} else {
text.setText(Html.fromHtml("hello this is 🔍"));
}


 
NOTE: many times what ever icon we need it's not availabe in HTML ICON system.Again Same Issue faced so better way 1st step is good. hello this is 🔍 image add inside text. //only HTML System working

Contributer

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Hot-product

Best Watch Store

Popular Posts

Contact Form

Name

Email *

Message *