2017年2月26日 星期日

Alert Dialog

Alert Dialog



Alert Dialog  :警報提示視窗。它可以顯示一個標題、最多三個按鈕、一系列可選取項目。


        為了產生Alert Dialog ,需要AlertDialogBuilder 類別。
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);


      我們需要positive(yes) 或negative (no) 的按鈕,來使用AlertDialogBuilder 類別。


alertDialogBuilder.setPositiveButton(CharSequencetext, DialogInterface.OnClickListener listener)



alertDialogBuilder.setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener)

Alert Dialog 的屬性:


  setIcon(Drawable icon):設置Alert Dialog的圖像
  dialog.setIcon(R.drawable.logo);--->圖片放在draeable/logo.png


  setCancelable(boolean cancel able)
    true開啟Android系統的主要功能鍵(menu,home等...)
     false 關閉 Android 系統的主要功能鍵(menu,home等...)


     setMessage(CharSequence message)設置Alert Dialog的顯示內容

     setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener)設置Alert Dialog多選清單(複選)

           setOnCancelListener(DialogInterface.OnCancelListener onCancelListener):當使用者按返回鍵,就會返回。


   setTitle(CharSequence title)Alert Dialog的標題


    setItemAlert Dialog的列表項目內容


    Show:顯示Alert Dialog。

   setPositiveButtonAlert Dialog加入yes 的按鈕。

   setNegativeButtonAlert Dialog加入no的按鈕。

   setNeutralButton Alert Dialog加入取消的按鈕。

  設定、顯示Alert Dialog


AlertDialog alertDialog=alertDialogBuilder.create();

alertDialog.show();


 DialogFragment一個浮動在畫面上的對話框,經常與使用者有互動的畫面。例如:輸入帳號密碼....等。

 List dialog:呈現列表的對話框


Single-choice list dialog:單一選擇列表的對話框。



參考文獻

Android Alert Dialog

Android警告對話框教程

Android Alertdialog(警告對話框)

[Android]AlertDialog(加入按鈕、加入List以及塞入一個Layout)

[Android] AlertDialog

Android─Dialog顯示時,不能按home與back button及dialog以外的區域(setCancelable)

【菜逼八學Android】顯示AlertDialog視窗(2)
 真希望天天都是星期天之 AlertDialog & CheckBox
(setMultiChoiceItems)例子OK
http://blog.wenyen.idv.tw/2013/10/alertdialog-checkbox.html

[Android] AlertDialog-加入多選列表並取得選擇結果(Multi choice list)

Android學習筆記常見對話框AlertDialog

AlertDialog詳解
http://changlingwu001.blogspot.tw/2015/04/alertdialog.html

如何使用DialogFragment

Android 官方推荐 : DialogFragment 创建对话框

Fragment子類別之DialogFragment

Dialog對話框詳解

對話方塊

Android dialog Single Choice Items(Single-choice list dialog)https://mossila.wordpress.com/2011/05/10/android-dialog-single-choice-items/

Dialog with Single Choice : Dialog « UI « Android


DialogFragment(Single Choice)



沒有留言:

張貼留言