先定义一个ImageView 和 TextView以及自定义一个布局。设置mTextView中的内容,并使用Linkfy使之能上网,将没TextView中的内容使用Toast显示出来,将Toast内容转变成View对象(才能使用Layout布局),将图片与文 字加进布局中,将Layout传入,显示。
private OnClickListener listener = new OnClickListener() {
public void onClick(View v) {// TODO Auto-generated method stub
ImageView mView01 = new ImageView(MainActivity.this);
TextView mTextView = new TextView(MainActivity.this);
LinearLayout lay = new LinearLayout(MainActivity.this);
mTextView.setText("www.baidu.com");
//判断mTextView内容如何,并与系统连接
Linkify.addLinks(mTextView, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES|Linkify.PHONE_NUMBERS);
//用Toast方式显示
Toast toast = Toast.makeText(MainActivity.this, mTextView.getText(), Toast.LENGTH_SHORT);
//自定义View对象
View textView = toast.getView();
//以水平方式排列
lay.setOrientation(LinearLayout.HORIZONTAL);
//指定显示的图片
mView01.setImageResource(R.drawable.ic_launcher);
lay.addView(mView01);
lay.addView(textView);
toast.setView(lay);
toast.show();
}
};