日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android---AlertDialog

發(fā)布時(shí)間:2024/4/15 Android 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android---AlertDialog 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

代碼如下:

//創(chuàng)建一個(gè)AlertDialogAlertDialog.Builder ad=new AlertDialog.Builder(this);//標(biāo)題ad.setTitle(R.string.alert_dialog_title_txt);//內(nèi)容ad.setMessage(R.string.alert_dialog_message_txt);// Positive Buttonad.setPositiveButton(R.string.alert_dialog_positive_txt, new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {TODO: 15/6/3Log.d(TAG,"++++++用戶點(diǎn)擊了 Positive Button");}});// Negative Buttonad.setNegativeButton(R.string.alert_dialog_negative_txt, new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {TODO: 15/6/3Log.d(TAG,"-------用戶點(diǎn)擊了 Negative Button");}});//Cancel Button/**ad.setCancelable(boolean b);* 用戶在沒有做任何選擇而按下“返回鍵”時(shí)是否應(yīng)該關(guān)閉AlertDialog* true :可以關(guān)閉* false : 不可以關(guān)閉* *///AlertDialog可以取消ad.setCancelable(true);ad.setOnCancelListener(new DialogInterface.OnCancelListener() {@Overridepublic void onCancel(DialogInterface dialog) {TODO: 15/6/3Log.d(TAG,"******用戶選擇了取消");}});//AlertDialog showad.show();
效果如下:



當(dāng)用戶點(diǎn)擊“Yes” ,“No”和物理返回鍵時(shí),可以觸發(fā)相應(yīng)的事件:

1》當(dāng)用戶點(diǎn)擊了“Yes”時(shí):

06-04 10:14:14.719 31083-31083/com.demo3.cxc.actionbardemo3 D/MainActivity﹕ ++++++用戶點(diǎn)擊了 Positive Button2》當(dāng)用戶點(diǎn)擊了“No”時(shí):

06-04 10:15:10.559 31083-31083/com.demo3.cxc.actionbardemo3 D/MainActivity﹕ -------用戶點(diǎn)擊了 Negative Button
3》當(dāng)用戶點(diǎn)擊返加鍵時(shí):

06-04 10:15:45.329 31083-31083/com.demo3.cxc.actionbardemo3 D/MainActivity﹕ ******用戶選擇了取消


總結(jié)

以上是生活随笔為你收集整理的Android---AlertDialog的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。