可以使用AlertDialog.Builder 才產(chǎn)生一個(gè)提示框
創(chuàng)新互聯(lián)專(zhuān)注于盧龍網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供盧龍營(yíng)銷(xiāo)型網(wǎng)站建設(shè),盧龍網(wǎng)站制作、盧龍網(wǎng)頁(yè)設(shè)計(jì)、盧龍網(wǎng)站官網(wǎng)定制、微信小程序服務(wù),打造盧龍網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供盧龍網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。
首先最簡(jiǎn)單的是彈出一個(gè)消息框:
new AlertDialog.Builder(self) .setTitle("標(biāo)題") .setMessage("簡(jiǎn)單消息框") .setPositiveButton("確定", null) .show();
效果如下:
帶確認(rèn)和取消按鈕的對(duì)話(huà)框:
new AlertDialog.Builder(self) .setTitle("是嗎") .setMessage("是嗎?") .setPositiveButton("是", null) .setNegativeButton("否", null) .show();
可以輸入文本的對(duì)話(huà)框:
new AlertDialog.Builder(self) .setTitle("請(qǐng)輸入文本:") .setIcon(android.R.drawable.ic_dialog_info) .setView(new EditText(self)) .setPositiveButton("確定", null) .setNegativeButton("取消", null) .show();
單選框:
new AlertDialog.Builder(self) .setTitle("請(qǐng)選擇:") .setIcon(android.R.drawable.ic_dialog_info) .setSingleChoiceItems(new String[] {"選項(xiàng)1","選項(xiàng)2","選項(xiàng)3","選項(xiàng)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[] {"選項(xiàng)1","選項(xiàng)2","選項(xiàng)3","選項(xiàng)4"}, null, null) .setPositiveButton("確定", null) .setNegativeButton("取消", null) .show();
列表對(duì)話(huà)框:
new AlertDialog.Builder(self) .setTitle("列表框") .setItems(new String[] {"列表項(xiàng)1","列表項(xiàng)2","列表項(xiàng)3"}, null) .setNegativeButton("確定", null) .show();
在對(duì)話(huà)框中顯示圖片:
ImageView img = new ImageView(self); img.setImageResource(R.drawable.icon); new AlertDialog.Builder(self) .setTitle("圖片框") .setView(img) .setPositiveButton("確定", null) .show();
事件處理:
帶一個(gè)確定的對(duì)話(huà)框
new AlertDialog.Builder(this) .setMessage("這是第二個(gè)提示") .setPositiveButton("確定", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialoginterface, int i){ //按鈕事件 } }) .show();
有確定和取消的對(duì)話(huà)框
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();