Android-對話方塊

來源:互聯網
上載者:User

標籤:android   ui   對話方塊   設計模式   

Android-對話方塊 一 實現對話方塊的步驟Dialog
1 常用對話方塊:

AlertDialog(彈出對話方塊)


DatePickerDialog(日期選擇對話方塊)


TimePickerDialog(時間選擇對話方塊)



構建方法:

AlertDialog _alertDialog = new AlertDialog.Builder(MyContentMenuActivity.this).create();
builder設計模式適用於,構造參數較多的時候


2 建立步驟:
在onCreateDialog方法中建立一個AlertDialog.Builder執行個體
AlertDialog.set相應的屬性
build執行個體.create()產生一個AlertDialog的執行個體
AlertDialog.show(),在show的時候也會create()


3 建立按鈕:
在builder的時候調用setPositiveButton() and setNegativeButton()方法
 


二 自訂Dialog
1 直接利用基類Dialog的對象來setContentView來呈現不同的Dialog,可以看出Dialog與
Activity非常相似


2 利用AlertDialog建立的對象來直接setView即可實現自訂 
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());


    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater(); 


    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout


    builder.setView(inflater.inflate(R.layout.dialog_signin, null))
3 如果想要自訂對話方塊,就用活動來作為對話方塊,而不是使用對話方塊API。
簡單建立一個活動並在<activity>清單manifest元素設定主題為Theme.Holo.Dialog。
<activity android:theme="@android:style/Theme.Holo.Dialog" >

Android-對話方塊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.