1 package com.turboradio.googlesdk;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.text.util.Linkify;
6 import android.view.View;
7 import android.widget.ImageView;
8 import android.widget.LinearLayout;
9 import android.widget.TextView;
10 import android.widget.Toast;
11
12 public class Ex5_7 extends Activity {
13
14 @Override
15 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.ex_5_7);
18
19 }
20 /**按钮监听器**/
21 public void showToast(View v){
22 ImageView imageView = new ImageView(Ex5_7.this);
23 TextView textView = new TextView(Ex5_7.this);
24 /**创建线性布局对象**/
25 LinearLayout lay = new LinearLayout(Ex5_7.this);
26 textView.setText("Show toast");
27 /**判断textView**/
28 Linkify.addLinks(textView, Linkify.WEB_URLS|Linkify.PHONE_NUMBERS|Linkify.EMAIL_ADDRESSES);
29 Toast toast = Toast.makeText(Ex5_7.this, textView.getText().toString(), Toast.LENGTH_LONG);
30 /**自定义View对象**/
31 View view = toast.getView();
32 /**水平布局**/
33 lay.setOrientation(LinearLayout.HORIZONTAL);
34 imageView.setBackgroundResource(android.R.drawable.btn_plus);
35 lay.addView(imageView);
36 lay.addView(view);
37 toast.setView(lay);
38 toast.show();
39 }
40 }
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="vertical" >
6 <Button
7 android:id="@+id/button"
8 android:layout_width="wrap_content"
9 android:layout_height="wrap_content"
10 android:text="显示具有图片的Toast"
11 android:onClick="showToast"
12 />
13 </LinearLayout>