package com.example.test1;
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 MainActivity extends Activity {
//布局中的视图都要声明成员变量
Button bn1;
//程序启动会调用onCreate方法
@Override
protected void onCreate(Bundle savedInstanceState) {
//调用父类的oncreate方法进行一些初始化操作
super.onCreate(savedInstanceState);
//加载布局,并生成对应试图对象
setContentView(R.layout.activity_main);
//得到到button对象
bn1 = (Button) findViewById(R.id.button1);
bn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast toast = Toast.makeText(getApplicationContext(), "吐司吐司", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
//提示开始出现的吐司
ImageView imageCodeProject = new ImageView(getApplicationContext());
//图片位置
imageCodeProject.setImageResource(R.drawable.o_li);
toastView.addView(imageCodeProject, 0);
//设置弹出的时间
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 MainActivity extends Activity {
//布局中的视图都要声明成员变量
Button bn1;
//程序启动会调用onCreate方法
@Override
protected void onCreate(Bundle savedInstanceState) {
//调用父类的oncreate方法进行一些初始化操作
super.onCreate(savedInstanceState);
//加载布局,并生成对应试图对象
setContentView(R.layout.activity_main);
//得到到button对象
bn1 = (Button) findViewById(R.id.button1);
bn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast toast = Toast.makeText(getApplicationContext(), "吐司吐司", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
//提示开始出现的吐司
ImageView imageCodeProject = new ImageView(getApplicationContext());
//图片位置
imageCodeProject.setImageResource(R.drawable.o_li);
toastView.addView(imageCodeProject, 0);
//设置弹出的时间
toast.show();
}
});
}
}