您好,登錄后才能下訂單哦!
可以使用AlertDialog.Builder 才產生一個提示框
首先最簡單的是彈出一個消息框:
new AlertDialog.Builder(self) .setTitle("標題") .setMessage("簡單消息框") .setPositiveButton("確定", null) .show();
效果如下:
帶確認和取消按鈕的對話框:
new AlertDialog.Builder(self) .setTitle("是嗎") .setMessage("是嗎?") .setPositiveButton("是", null) .setNegativeButton("否", null) .show();
可以輸入文本的對話框:
new AlertDialog.Builder(self) .setTitle("請輸入文本:") .setIcon(android.R.drawable.ic_dialog_info) .setView(new EditText(self)) .setPositiveButton("確定", null) .setNegativeButton("取消", null) .show();
單選框:
new AlertDialog.Builder(self) .setTitle("請選擇:") .setIcon(android.R.drawable.ic_dialog_info) .setSingleChoiceItems(new String[] {"選項1","選項2","選項3","選項4"}, 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } } ) .setNegativeButton("取消", null) .show();
多選框:
new AlertDialog.Builder(self) .setTitle("多選框") .setMultiChoiceItems(new String[] {"選項1","選項2","選項3","選項4"}, null, null) .setPositiveButton("確定", null) .setNegativeButton("取消", null) .show();
列表對話框:
new AlertDialog.Builder(self) .setTitle("列表框") .setItems(new String[] {"列表項1","列表項2","列表項3"}, null) .setNegativeButton("確定", null) .show();
在對話框中顯示圖片:
ImageView img = new ImageView(self); img.setImageResource(R.drawable.icon); new AlertDialog.Builder(self) .setTitle("圖片框") .setView(img) .setPositiveButton("確定", null) .show();
事件處理:
帶一個確定的對話框
new AlertDialog.Builder(this) .setMessage("這是第二個提示") .setPositiveButton("確定", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialoginterface, int i){ //按鈕事件 } }) .show();
有確定和取消的對話框
new AlertDialog.Builder(this) .setTitle("提示") .setMessage("確定退出?") .setIcon(R.drawable.quit) .setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setResult(RESULT_OK);//確定按鈕事件 finish(); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //取消按鈕事件 } }) .show();
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。