1. 程式人生 > >高級控件【安卓5】——信息提示框、對話框

高級控件【安卓5】——信息提示框、對話框

make 安卓 com log list 股市 message bundle gif

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 });
警告框

技術分享

高級控件【安卓5】——信息提示框、對話框