以AlertDialog為例
目前創(chuàng)新互聯(lián)已為上千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、孫吳網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
一、將AlertDialog視圖封裝在dialogfragment(fragmentdeAlertDialog子類)實(shí)例中
package com.example.t;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.DatePicker;
public class DialogPickerFragment extends android.support.v4.app.DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePicker dp = new DatePicker(getActivity());
return new AlertDialog.Builder(getActivity())
.setView(dp)
.setTitle("Dialog")
.setPositiveButton("OK", null)
.create();
}
}
二、在activity中調(diào)用
public void dialogpicker(View v) {
FragmentManager fm = getSupportFragmentManager();
DialogPickerFragment dialog = new DialogPickerFragment();
dialog.show(fm, "date");
}