public class MainActivity extends Activity {
TextView tv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView1);
tv1.setText(Html.fromHtml("<a href='http://www.baidu.coms'>百度</a>"+"<a href='tel:1312343'>电话</a>"));
tv.setMovementMethod(LinkMovementMethod.getInstance());
//下面的tv再一次定义了setText那么前面定义的“百度"连接将会被下面的图片覆盖,运行结果不会出现百度连接,值出现图片。
tv.setText(Html.fromHtml("<img src='vvv'/>", new ImageGetter() {
@Override
public Drawable getDrawable(String source) {
// TODO Auto-generated method stub
Drawable dr = null ;
try {
dr = getResources().getDrawable(
R.drawable.class.getField(source)
.getInt(null));
//先得到drawable.class类,再得到里面的vvv=0x7f020001相当于于一个标志,就得到了这张图片
dr.setBounds(0,0,dr.getIntrinsicWidth()
, dr.getIntrinsicHeight());//设置图片大小
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dr;
}
},null));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}