实现效果如下:Toast中添加图片,让图片显示的方法
实现的代码如下;
package mldn.lxd.toasttest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class ToastTestProjectActivity extends Activity {
Button button = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) super.findViewById(R.id.btnToastTest);
button.setOnClickListener( new myToastTestOnclickListener());
}
private final class myToastTestOnclickListener implements OnClickListener
{
@Override
public void onClick(View v)
{
Toast toast = Toast.makeText(ToastTestProjectActivity. this, "李小道是个牛逼的人吗?", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 20, 69);
LinearLayout linearLayout =(LinearLayout)toast.getView();
ImageView imageView = new ImageView(ToastTestProjectActivity. this);
imageView.setImageResource(R.drawable.myimg);
linearLayout.addView(imageView, 1);
toast.setView(linearLayout);
toast.show();
}
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class ToastTestProjectActivity extends Activity {
Button button = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) super.findViewById(R.id.btnToastTest);
button.setOnClickListener( new myToastTestOnclickListener());
}
private final class myToastTestOnclickListener implements OnClickListener
{
@Override
public void onClick(View v)
{
Toast toast = Toast.makeText(ToastTestProjectActivity. this, "李小道是个牛逼的人吗?", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 20, 69);
LinearLayout linearLayout =(LinearLayout)toast.getView();
ImageView imageView = new ImageView(ToastTestProjectActivity. this);
imageView.setImageResource(R.drawable.myimg);
linearLayout.addView(imageView, 1);
toast.setView(linearLayout);
toast.show();
}
}
}