/** * @Title CustomWidgeActivity.java * @package cn.boxai.customview * @since * @version 1.0.0 * @author Vic Lee * @date Aug 22, 2016-8:15:35 PM */ package cn.boxai.customview; import android.R.string; import android.app.Activity; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.Html; import android.text.Html.ImageGetter; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.ClickableSpan; import android.text.style.ImageSpan; import android.view.View; import android.widget.TextView; import android.widget.Toast; public class CustomWidgeActivity extends Activity { TextView mTextView; ImageGetter getter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_customwidge); showTextView() ; } protected void showTextView() { // getter=new ImageGetter() // { // // @Override // public Drawable getDrawable(String source) { // if (source!=null) // { // BitmapDrawable bitmapDrawable=(BitmapDrawable) getResources().getDrawable(R.drawable.aa); // bitmapDrawable.setBounds(0, 0,bitmapDrawable.getIntrinsicWidth(), bitmapDrawable.getIntrinsicWidth()); // return bitmapDrawable; // } // else // { // return null; // } // // } // }; // mTextView=(TextView) findViewById(R.id.textView1); // String html="<h1>ddddddddddddsfsf</h1></br>ddddddd </br><img src='http://pic.cnblogs.com/face/800469/20160120232307.png'/ ddsfdsaf>"; // mTextView.setText(Html.fromHtml(html, getter, null)); mTextView=(TextView) findViewById(R.id.textView1); SpannableStringBuilder spannableStringBuilder=new SpannableStringBuilder(" hello world!"); ImageSpan imageSpan=new ImageSpan(CustomWidgeActivity.this,R.drawable.aa); ClickableSpan clickableSpan=new ClickableSpan() { @Override public void onClick(View widget) { Toast.makeText(CustomWidgeActivity.this, " you are click", 3000).show(); } }; spannableStringBuilder.setSpan(imageSpan, 3, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannableStringBuilder.setSpan(clickableSpan, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); mTextView.setText(spannableStringBuilder); } }