以AlertDialog为例
一、将AlertDialog视图封装在dialogfragment(fragmentdeAlertDialog子类)实例中
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中调用
public void dialogpicker(View v) {
FragmentManager fm = getSupportFragmentManager();
DialogPickerFragment dialog = new DialogPickerFragment();
dialog.show(fm, "date");
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。