Toast信息提示框
1 Button bt1=(Button)findViewById(R.id.Tbt01); 2 Button bt2=(Button)findViewById(R.id.Tbt02); 3 bt1.setOnClickListener(new OnClickListener() { 4 public void onClick(View v) { 5 Toast.makeText(Toast0.this, "按钮1短提示", 6 Toast.LENGTH_SHORT).show(); 7 } 8 }); 9 bt2.setOnClickListener(new OnClickListener() { 10 public void onClick(View v) { 11 Toast.makeText(Toast0.this, "按钮2长提示", 12 Toast.LENGTH_LONG).show(); 13 } 14 });
信息提示框
Dialog(对话框)、AlertDialog(警告框)
1 protected void onCreate(Bundle savedInstanceState) { 2 super.onCreate(savedInstanceState); 3 setContentView(R.layout.dialog); 4 bt = (Button) findViewById(R.id.Dbt); 5 bt.setOnClickListener(new OnClickListener() { 6 public void onClick(View v) { 7 Dialog dialog=new AlertDialog.Builder(Dialog0.this) 8 .setTitle("警告") //设置标题 9 .setMessage("股市有风险,投资需谨慎") //显示信息 10 .setIcon(R.drawable.go) //设置显示的图片 11 .create(); //创建Dialog 12 dialog.show(); //显示对话框 13 } 14 });
警告框
时间: 2024-10-27 19:23:22