Android如何在TextView中显示图片

import android.app.Activity; 
import android.graphics.drawable.Drawable; 
import android.os.Bundle; 
import android.text.Html; 
import android.text.Html.ImageGetter; 
import android.widget.TextView; 
 
public class TextViewDemoActivity extends Activity { 
 
    private TextView txtWecome; 
 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        setupViews(); 
    } 
 
    private void setupViews() { 
        txtWecome = (TextView) findViewById(R.id.wecome); 
        txtWecome.append(Html.fromHtml("<img src='"+R.drawable.ok+"'/>", imageGetter, null)); 
    } 
 
    ImageGetter imageGetter = new ImageGetter() { 
 
        @Override 
        public Drawable getDrawable(String source) { 
            int id = Integer.parseInt(source); 
            Drawable drawable = getResources().getDrawable(id); 
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight()); 
            return drawable; 
        } 
    }; 
}

你可能感兴趣的:(Android如何在TextView中显示图片)