Android AlertDialog学习
生活随笔
收集整理的這篇文章主要介紹了
Android AlertDialog学习
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 有兩個按鈕的對話框
Builder builder=new AlertDialog.Builder(AlertDialogActivity.this); builder.setIcon(android.R.drawable.btn_plus); builder.setTitle("btnplus"); builder.setMessage("去不去?"); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { Toast.makeText(AlertDialogActivity.this,"你選擇了確定按鈕",Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton("取消",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { Toast.makeText(AlertDialogActivity.this, "你選擇了取消按鈕",Toast.LENGTH_SHORT).show(); } } ); builder.show(); }2. ?帶有三個按鈕的對話框
public void onClick(View v) { // TODO Auto-generated method stub new AlertDialog.Builder(AlertDialogActivity.this) .setIcon(android.R.drawable.btn_star).setTitle("溫馨提示").setMessage("提示內容,三個按鈕"). setPositiveButton("確定",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(AlertDialogActivity.this, "你選擇了確定按鈕", Toast.LENGTH_SHORT).show(); } }) .setNeutralButton("菜單",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(AlertDialogActivity.this, "你選擇了詳細按鈕", Toast.LENGTH_SHORT).show(); } }) .setNegativeButton("取消",new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog,int which){ Toast.makeText(AlertDialogActivity.this,"你選擇了取消按鈕",Toast.LENGTH_SHORT).show(); } }) .show(); }3. 能進行輸入的對話框
public void onClick(View v) { // TODO Auto-generated method stub LayoutInflater inflater=LayoutInflater.from(AlertDialogActivity.this); final View textEntryView=inflater.inflate(R.layout.alert_dialog_text_entry,null); final EditText usernameET=(EditText)textEntryView.findViewById(R.id.username_value); final EditText passwordET=(EditText)textEntryView.findViewById(R.id.password_value);new AlertDialog.Builder(AlertDialogActivity.this) .setIcon(android.R.drawable.btn_star) .setTitle("溫馨提示") .setView(textEntryView) .setPositiveButton("確定",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { Toast.makeText(AlertDialogActivity.this,"用戶名="+usernameET.getText().toString()+"\n密碼="+passwordET.getText().toString(),Toast.LENGTH_SHORT).show(); } }) .setNegativeButton("取消",new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog,int which) { Toast.makeText(AlertDialogActivity.this,"你選擇了取消按鈕",Toast.LENGTH_SHORT).show(); } }) .show();4. 進度條對話框
ProgressDialog dialog=new ProgressDialog(AlertDialogActivity.this); dialog.setTitle("處理中。。。"); dialog.setMessage("請稍等。。。"); dialog.show();轉載于:https://www.cnblogs.com/cc-Cheng/archive/2012/07/20/2714101.html
總結
以上是生活随笔為你收集整理的Android AlertDialog学习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 海量小文件存储
- 下一篇: (转)VS2010 快捷键