Making GoSmsPro/Evernote like EditText

The first thing that user notes in your app is User Interface(how it looks) and of course it matters . Keeping those things on my mind I tried to implement EditText with TextView with some pleasing background which itself tells the user that it can be touched and when get touched it will be deleted. Something like this

Yes,I am exactly talking about what GoSmsPro or Evernote app has done before for better user experience.Recently, I implemented this kind of UI in my app Sms Scheduler which you can find in Google play. Here are the steps how you can implement in your app.

Create a TextView Dynamically

public TextView createContactTextView(String text){
  TextView tv = new TextView(this);
  tv.setCompoundDrawablesWithIntrinsicBounds(0, 0,android.R.drawable.presence_offline, 0);
  return tv;

where bubble is xml file which should be in res/color folder

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="">
  <stroke android:width="1dp" android:color="#A6B0B8" />
	<gradient android:startColor="#E5E5E6"
	<corners  android:bottomRightRadius="10dp" 

Convert TextView to drawable

public static Object convertViewToDrawable(View view) {
  int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
  view.measure(spec, spec);
  view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
  Bitmap b = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
  Canvas c = new Canvas(b);
  c.translate(-view.getScrollX(), -view.getScrollY());
  Bitmap cacheBmp = view.getDrawingCache();
  Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
  return new BitmapDrawable(viewBmp);


How to make bubble clickable

you have to add few lines of code before setting it on edit-text. Beside Image Span you also have to set clickable Span something like this

 ClickableSpan clickSpan = new ClickableSpan() {

			public void onClick(View view) { 
				Log.v("clicked", view.getClass().getSimpleName());

				int i = ((EditText) view).getSelectionStart();
				int j = ((EditText) view).getSelectionEnd();
				phoneNum.getText().replace(Math.min(i, j ),
						Math.max(i, j ), "", 0, "".length());

		sb.setSpan(clickSpan, sb.length() - contactname.length(),
				sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Note: you have to set MovementMethod to LinkMovementMethod for ClickableSpan to work something like this


finally you implement like this

final SpannableStringBuilder sb = new SpannableStringBuilder();
TextView tv = createContactTextView(contactName);
BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(tv);
bd.setBounds(0, 0, bd.getIntrinsicWidth(),bd.getIntrinsicHeight());

sb.append(contactName + ",");
sb.setSpan(new ImageSpan(bd), sb.length()-(contactName.length()), sb.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
sb.setSpan(clickSpan, sb.length() - contactname.length(),
				sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

The final output look like

If you find difficult to implement the concept,I have pushed the source code in github
enjoy with android 🙂